Monday, 30 December 2013

MS SQL 2013 - How to fix error - Must declare the scalar variable

Watch this example on YouTube



Replace

DECLARE @Customer VARCHAR(20)

SET @Customer = '1'

Declare @sql varchar(max)

Set @sql = 'SELECT * FROM CustomerMaster '

Set @sql = @sql + 'WHERE CustomerID =  @Customer'

Execute(@sql)

With

DECLARE @Customer VARCHAR(20)

SET @Customer = '1'

Declare @sql varchar(max)

Set @sql = 'SELECT * FROM CustomerMaster '

Set @sql = @sql + 'WHERE CustomerID = ' +@Customer

Execute(@sql)

No comments:

Post a Comment