minglelinch
asked on
a tsql question
I can select records with the following statement -
select [id], [location], fn as 'firstname', ln as 'lastname'
from dbo.mytable
where fn like 'Mike%'
I need to change to the following query, why I cannot select any record?
declare @ttt varchar(10)
set @ttt = '''' + 'Mike' + '%' + ''''
--print @ttt
select [id], [location], fn as 'firstname', ln as 'lastname'
from dbo.mytable
where fn like @ttt
when I print @ttt, it has the value 'Mike%'. I'm wondering why I cannot select any record after I replace 'Mike%' with a variable having the same value in the where clause.
Please help. Thanks.
select [id], [location], fn as 'firstname', ln as 'lastname'
from dbo.mytable
where fn like 'Mike%'
I need to change to the following query, why I cannot select any record?
declare @ttt varchar(10)
set @ttt = '''' + 'Mike' + '%' + ''''
--print @ttt
select [id], [location], fn as 'firstname', ln as 'lastname'
from dbo.mytable
where fn like @ttt
when I print @ttt, it has the value 'Mike%'. I'm wondering why I cannot select any record after I replace 'Mike%' with a variable having the same value in the where clause.
Please help. Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER