You are here: Re: Newbie with SQL Server Trigger « MsSQL Server « IT news, forums, messages
Re: Newbie with SQL Server Trigger

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация