Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Weird behaviour with Variables of a Stored Procedure

$
0
0

Hello All,

   I'm writing following stored procedure and it is failing with following error

"Conversion failed when converting from a character string to uniqueidentifier"

 What's Happening?

  I've created

Create Procedure usp_Sample

AS

Declare @Var Int

Select @Var = Key From MyKeyTable Where Name = 'XYZ'

Select * From BaseTable A

LEFT JOIN JoinTable B

ON A.UniqueIdentifierField = CONVERT(UNIQUEIDENTIFIER,B.VarcharField)

AND B.Key = @Var

GO

Procedure got created and when you execute it you see the above error...

If I remove the Variable and HardCode it with any value then it runs fine...

Could someone tell me what is wrong with the variable here? (I Can't hardcode the Variable Value In the Proc).

"BaseTable" has a field that is UniqueIdentifier and "JoinTable" has a NVARCHAR (1020) Field. But JoinTable has proper UniqueIdentifier data. 

Let me know if you need anymore info...

--Roger


Unknown


Viewing all articles
Browse latest Browse all 23857

Trending Articles