Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Please help me Debug

Author  Topic 

Sarathchandra
Starting Member

2 Posts

Posted - 2015-03-28 : 07:55:18
Hi, I am new to SQl I have written a code which is as follows but gives an error
Msg 102, Level 15, State 1, Line 6
Incorrect syntax near 'SALARY'.


Please find the code below

Create Table Person(ID INT, NAME NVARCHAR(255),SALARY INT, JDATE DATETIME,CITY NVARCHAR(255),REGION CHAR(255))
insert into Person(ID,NAME,SALARY,JDATE,CITY,REGION)VALUES(1,'MEGAN',25000, '02/01/96','UTAH','W')
insert into Person(ID,NAME,SALARY,JDATE,CITY,REGION)VALUES(2,'BRUCE',35000, '02/05/96','NEWYORK','E')
insert into Person(ID,NAME,SALARY,JDATE,CITY,REGION)VALUES(3,'KAI',27000, '02/06/97','CHICAGO','S')
insert into Person(ID,NAME,SALARY,JDATE,CITY,REGION)VALUES(4,'TYSON',28000, '02/01/96','TEXAS','W')
insert into Person(ID,NAME,SALARY,JDATE,CITY,REGION)VALUES(5,'BROOKLYN',29000, '02/07/94','BROOKLYN','W')
insert into Person(ID,NAME,SALARY,JDATE,CITY,REGION)VALUES(6,'RAY',30000, '02/01/98','PARIS','W')
insert into Person(ID,NAME,SALARY,JDATE,CITY,REGION)VALUES(7,'MAX',31000, '22/1/96','LONDON','W')
SELECT * FROM Person
SELECT ID
CASE
WHEN SALARY=30000 THEN 6
WHEN SALARY=35000 THEN 2
ELSE
NO SALARY PRESENT
END
go


Please help me with the correct syntax


Sarath chandra

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2015-03-28 : 08:41:35
I didn't understand the logic you are trying to implement, but the way you are using the case expression and the table names are syntactically incorrect. Try this - it may not give you the logic you are looking for, but it has the correct syntax
SELECT * FROM Person;

SELECT ID,
CASE
WHEN SALARY=30000 THEN '6'
WHEN SALARY=35000 THEN '2'
ELSE 'No Salary'
END
from Person

go
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2015-03-28 : 11:23:13
Duplicate post of this thread:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=200553
Go to Top of Page
   

- Advertisement -