Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello..

SQL
DECLARE @_id int 
SET @_id = select TOP 1(_id) from tbl_User where _userName like '%'+ @createdBy+'%';


What is mistake in query. please help. . .
Posted

write as below
SQL
DECLARE @_id int 
select TOP 1 @_id = _id from tbl_User where _userName like '%'+ @createdBy+'%';
print @_id;

Happy Coding!
:)
 
Share this answer
 
Comments
damodara naidu betha 19-Jun-13 2:39am    
5+
Aarti Meswania 19-Jun-13 2:40am    
Thank you!
:)
You need inverted quotes -
select TOP 1(_id) from tbl_User where _userName like '''%'+ @createdBy+'''%';
 
Share this answer
 
Comments
[no name] 23-May-13 4:52am    
Steel i got same error "Msg 156, Level 15, State 1, Procedure advSearch, Line 16
Incorrect syntax near the keyword 'select'."
DECLARE @_id int
SET @_id = (select TOP 1(_id) from tbl_User where _userName like '%'+ @createdBy+'%')
SELECT @_id


just put bracket
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900