Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2005
The version you posted originally was correct. Neither of the below would work. If, for example, you declared @Arg as char(20) instead of varchar(20) that would produce the result you are seeing (but that's not the case in your example).
What type is 'Name' in the table (although I don't see this as a factor) ?
>>>Is the above an actual example ?
>Yep. Just doesn't work.
>I've tried grasping at straws, e.g.:
>SELECT * FROM Table WHERE Name LIKE '@Arg'
>SELECT * FROM Table WHERE Name LIKE '%@Arg%'
>
>
>Gary
>
>
>>>Hi All,
>>>I'm baffled by what should be a simple thing. I'm trying to use a parameter in a WHERE clause.
>>>A dirt simple example might be:
>>>
>>>declare @Arg varchar(20)
>>>SET @Arg = 'Joe%'
>>>
>>>SELECT * FROM Table WHERE Name LIKE @Arg
>>>
>>>I get nothing back from the above while SELECT * FROM Table WHERE Name LIKE 'Joe%' works like a champ.
>>>
>>>Clearly, I'm new to doing this. I really want to avoid dynamic SQL here!
>>>
>>>Any help is appreciated.
>>>
>>>Gary
>>
>>Don't think there's anything wrong in principal. Is the above an actual example ? If @Arg is dimensioned less than the string length assigned to it then you'd get nothing back.
Précédent
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement