473,382 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

USING 'CASE' TO GROUP DATA

PB
Hi,

Can anyone please help me with SQL syntax to create a second variable
based on the value of another (both numeric)?

My effort is below but I get a syntax error.

SELECT

charA,

CASE charA
WHEN < -199 THEN 2
WHEN < 31 THEN 3
WHEN < 82 THEN 4
WHEN < 100 THEN 5
WHEN < 105 THEN 6
WHEN < 111 THEN 7
WHEN < 143 THEN 8
WHEN < 165 THEN 9
WHEN < 233 THEN 10
WHEN >= 233 THEN 11
END AS Bin_charA

FROM X
Server: Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near '<'.

Aug 22 '06 #1
3 1969
On 22 Aug 2006 01:19:18 -0700, "PB" <ph**********@hotmail.comwrote:
>Hi,

Can anyone please help me with SQL syntax to create a second variable
based on the value of another (both numeric)?

My effort is below but I get a syntax error.

SELECT

charA,

CASE charA
WHEN < -199 THEN 2
WHEN < 31 THEN 3
WHEN < 82 THEN 4
WHEN < 100 THEN 5
WHEN < 105 THEN 6
WHEN < 111 THEN 7
WHEN < 143 THEN 8
WHEN < 165 THEN 9
WHEN < 233 THEN 10
WHEN >= 233 THEN 11
END AS Bin_charA

FROM X
Server: Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near '<'.
case
when CharA < -199 then 2
when CharA < 31 then 3
<etc.>
Aug 22 '06 #2
Your case structure is ok, btw you are missing a column title.
however, it looks like you are trying to compare a char type to an int
type.
Your numbers are not quoted to convert them to char, so.
either cast or charA to an int, or quote your values in the when.
HTH
Rob
PB wrote:
Hi,

Can anyone please help me with SQL syntax to create a second variable
based on the value of another (both numeric)?

My effort is below but I get a syntax error.

SELECT

charA,

CASE charA
WHEN < -199 THEN 2
WHEN < 31 THEN 3
WHEN < 82 THEN 4
WHEN < 100 THEN 5
WHEN < 105 THEN 6
WHEN < 111 THEN 7
WHEN < 143 THEN 8
WHEN < 165 THEN 9
WHEN < 233 THEN 10
WHEN >= 233 THEN 11
END AS Bin_charA

FROM X
Server: Msg 170, Level 15, State 1, Line 6
Line 6: Incorrect syntax near '<'.
Aug 22 '06 #3
oops, missed that you put 'AS' at then of case stucture.
PB wrote:
Hi,

Can anyone please help me with SQL syntax to create a second variable
based on the value of another (both numeric)?
WHEN >= 233 THEN 11
END AS Bin_charA
Aug 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DCM Fan | last post by:
{CREATE TABLEs and INSERTs follow...} Gents, I have a main table that is in ONE-MANY with many other tables. For example, if the main table is named A, there are these realtionships: A-->B...
3
by: chowda | last post by:
trying to get to the bottom of this for some time...... eventually to be used with asp. heres the problem the following rather complex SQL statement works fine via query analyser: SELECT...
37
by: Haines Brown | last post by:
I understand that <br /> is marginal in CSS, and so am looking for a substitute for the EOL character. I've failed in both approaches and seek advice. The first thing I tried was to use the...
0
by: Clifford Heath | last post by:
We've set up an SQL Server 2000 (build 8.0.761 - I think that's SP3) access control scenario like the one described in this article:...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
2
by: DaZeD | last post by:
Hi there every1, i've been stuck on a problem for longer then any1 could of expected... My problem is that i have a method that i have to call in C#, that comes from C++ DLL, easy enough to call a...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
by: bflemi3 | last post by:
My previous post went unanswered. I now know what the problem is but can not think of a practical work around. Hopefully by making my question less confusing someone will be able to help...here...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.