March 4, 2014 at 9:17 am
Below is the code but always get an error. How to fix it?
The goal is to search CLAIMNO LIKE '2014030480999001', '2014030480999002'...
999 is @operator based user ID.
Select CLAIMNO
FROM CLAIM_MASTERS
where CLAIMNO like''' + Convert(VARCHAR(20), Getdate(), 112) +'80' + Right('000' + @operator, 3) + '%'''
March 4, 2014 at 9:25 am
What is the error you are getting? That may help.
Also, it looks as if you are trying to use Dynamic SQL
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
March 4, 2014 at 9:30 am
Error:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near '000'.
Msg 105, Level 15, State 1, Line 3
Unclosed quotation mark after the character string '''.
March 4, 2014 at 9:38 am
You are concatenating the string incorrectly.
Change the last line to:
where CLAIMNO like Convert(VARCHAR(20), Getdate(), 112) +'80' + Right('000' + @operator, 3) + '%'
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
March 4, 2014 at 10:12 am
Thank you. It works now
March 4, 2014 at 10:43 am
This is a classic example of why you shouldn't shove multiple data elements into a single column. It is a serious PITA to work with.
_______________________________________________________________
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 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply