Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

4 Posts

Posted - 09/01/2010 :  11:41:06  Show Profile  Reply with Quote
I was wondering if newid() value is different even if newid() is used in 2 different places in the same sql statement, i.e, one newid() is select clause and another newid() in where clause

(tbl1.col1, NEWID())) as int))
% 100 FROM table1 tbl1
(tbl1.col1, NEWID())) as int))
% 100) < 20

The reason for my question: The results of the select do not seem to match with the where condition.

Thank you.


5072 Posts

Posted - 09/01/2010 :  11:49:48  Show Profile  Visit russell's Homepage  Reply with Quote
it will return 2 distinct values, so your query won't work. but you can do this

Declare @newid uniqueidentifier
set @newid = newid()

SELECT	*, ABS(CAST((BINARY_CHECKSUM(tbl1.col1, @newid)) as int)) % 100
FROM	table1 tbl1
WHERE	(ABS(CAST((BINARY_CHECKSUM(tbl1.col1, @newid)) as int)) % 100) < 20
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000