July 2, 2014 at 7:25 am
Hi Friends i have small doubt in sql server.
tabele data contains like
table:emp
id, name
1,abc
2,
3,n
4,ja
5, jied
6,null
when null or empty came replace with 9999 and avoid empty spaces i tried query like below
select coalesce(ltrim(rtrim(substring(name,1,5))) ,'') ='' then '9999' else substring(ltrim(rtrim(name),1,5) end name
FROM emp its not give output and
it shows error like
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '='.
please tell me query to solve this issue
July 2, 2014 at 7:36 am
asranantha (7/2/2014)
Hi Friends i have small doubt in sql server.tabele data contains like
table:emp
id, name
1,abc
2,
3,n
4,ja
5, jied
6,null
when null or empty came replace with 9999 and avoid empty spaces i tried query like below
select coalesce(ltrim(rtrim(substring(name,1,5))) ,'') ='' then '9999' else substring(ltrim(rtrim(name),1,5) end name
FROM emp its not give output and
it shows error like
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '='.
please tell me query to solve this issue
Try CASE. http://msdn.microsoft.com/en-us/library/ms181765.aspx
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply