Click here to Skip to main content
15,920,603 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii ,


Where Username = ''' + @Username + '''

This is part of my query which will be executed by sp_executesql procedure ..

Howerver . my username contains apstophe , vish;nu@gmail.com .. when i direct use @Username ... because of string .. it givem the error , as it conflicts between this apsotphe and last closing apsophe of the query .. please suggest
Posted

DON'T DO THAT! Use a parameterized query! Every time!
 
Share this answer
 
Comments
Torakami 10-Jun-14 1:41am    
Yes i am sending parametriced query only .. but i have to replace single apstophe two times
Use below mention syntax

SQL
Declare @sql_query NVARCHAR(500) = 'SELECT EID,ENAME FROM Employee WHERE DEPT = ''IT'''
--select @sql_query

EXECUTE  sp_executesql @sql_query
 
Share this answer
 
try this.. :)

SQL
DECLARE @strQuery nvarchar(max)='',@Username nvarchar(250)=''
select @strQuery ='select * from tableName where UserName='+ @Username
exec(@strQuery)
 
Share this answer
 

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