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 2000 Forums
 Transact-SQL (2000)
 Query Error Using CASE

Author  Topic 

AsimKhaliq
Yak Posting Veteran

94 Posts

Posted - 2003-12-06 : 16:55:27
Hi, Iam using below query but I have error
INSERT tableName
SELECT S.FiledID, C.Field2,C.Field3
Field4=Case
When Left(C.Field4, 2) = S.Field and isnumeric(Substring(C.Field4,3,10))=1 THEN 'NULL'
Else
(left(Field4,8)
End
FROM Table1 C inner join Table2
on C.FiledID = S.S.FiledID

My error is = which is Field4= case, can Anyone check for

Thanks in advance

TimChenAllen
Starting Member

45 Posts

Posted - 2003-12-06 : 17:43:52
quote:
Originally posted by AsimKhaliq
INSERT tableName 
SELECT S.FiledID, C.Field2,C.Field3
Field4=Case
When Left(C.Field4, 2) = S.Field and isnumeric(Substring(C.Field4,3,10))=1 THEN 'NULL'
Else
(left(Field4,8)
End
FROM Table1 C inner join Table2
on C.FiledID = S.S.FiledID



I don't really understand what the error is or what output you expect, but there is no way that the SQL you posted could work.
1) You're missing parentheses in the ELSE part of the case.
2) Unless you want the literal value 'NULL' in the field, don't put NULL in quotes.
3) Put a comma after field3.

What error message do you actually receive? Or does the query produce something you don't expect? Please slow down and write a better description of what you expect and what unexpected results you get.

--
Timothy Chen Allen
email me if you have a job in New Orleans for me
[url]http://www.timallen.org[/url]
Go to Top of Page
   

- Advertisement -