|
Posted by Erland Sommarskog on 02/21/07 22:51
(ricardo.sobral.santos@googlemail.com) writes:
> Yes that is something I was needing.
> I need to convert an Hex type to Varchar and use that as a id. I would
> like to use an integer but the cast would not work.
>
> I think I might have the answer.
>
> ALTER TRIGGER myTrigger_INSERT ON aspnet_Membership FOR INSERT AS
>
> --this is an INSERT FROM SELECT
> INSERT INTO WikedCompetitions.dbo.testTable
> SELECT
> CAST(userId AS VARCHAR(16)), --pay attention to the column sizes
> because of the uniqueidentifier type
You need char(36). A GUID is 128 bits, or 16 bytes. That's 32 bytes
as a string. To that comes some extra characters for the hyphens. See
this:
declare @guid uniqueidentifier
select @guid = newid()
select cast(@guid as char(36)), @guid
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Navigation:
[Reply to this message]
|