Reputation: 63
What's the problem with my query, it doesn't work
DECLARE @_old nvarchar = '@35_D'
DECLARE @_new nvarchar = '@Dima'
UPDATE ShoppingComment SET Commnet =Replace(Commnet,@_old,@_new)
It doesn't show error, but query isn't replace, but when I use it without DECLARE , it works fine
Upvotes: 0
Views: 45
Reputation: 93694
Datatype
length is missing in your code.
From MSDN
When n is not specified in a data definition or variable declaration statement, the default length is 1.
So only the first character will be assigned to the variable
DECLARE @_old nvarchar(50) = '@35_D' --here
DECLARE @_new nvarchar(50) = '@Dima' --here
UPDATE ShoppingComment SET Commnet =Replace(Commnet,@_old,@_new)
Upvotes: 5