Home All Groups Group Topic Archive Search About

Msg 402 aad uniqueidentifier to string

Author
24 Aug 2006 12:48 PM
Arjen
Hi,

I get this message:
The data types nvarchar and uniqueidentifier are incompatible in the add
operator.

I need to add an uniqueidentifier, this is what I have now:
[UserId] = ' + @UserId + '

@UserId is the uniqueidentifier.

How do I add this parameter?

Thanks!
Arjen

Author
24 Aug 2006 12:59 PM
Adi
You can use cast or convert functions:

select UserID + cast(@UserID as varchar(36)
from.....

or

select UserID + convert(varchar(36), @userID)
from....

Adi
Arjen wrote:
Show quote
> Hi,
>
> I get this message:
> The data types nvarchar and uniqueidentifier are incompatible in the add
> operator.
>
> I need to add an uniqueidentifier, this is what I have now:
> [UserId] = ' + @UserId + '
>
> @UserId is the uniqueidentifier.
>
> How do I add this parameter?
>
> Thanks!
> Arjen
Author
24 Aug 2006 1:14 PM
ML
Better yet (IMHO) - explain what you actually need, rather that posting a
fragment of what seems to by dynamic SQL. Perhaps you should read this fine
article on dynamic SQL by Erland Sommarskog:

http://www.sommarskog.se/dynamic_sql.html

Clue: "sp_executesql".


ML

---
http://milambda.blogspot.com/

AddThis Social Bookmark Button