February 6, 2008 at 12:26 am
Comments posted to this topic are about the item Random default string for a column using CASE and NEWID
June 14, 2012 at 3:14 am
SELECT
CAST(NEWID() AS CHAR(36)),
CASE CAST( ASCII (SUBSTRING( CAST( NEWID() AS VARCHAR(64)), 1, 1)) AS INT) % 2
WHEN 0 THEN 'OPTION 1' ELSE 'OPTION 2' END,
CASE ABS(CHECKSUM(NEWID()) % 2)
WHEN 0 THEN 'OPTION 1' ELSE 'OPTION 2' END
FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12)) r (n)
Uniqueidentifier CASTS more correctly to a CHAR(36)
ABS(CHECKSUM(NEWID()) is handy for generating a pseudo-random integer.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply