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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help looking for duplicates, with a twist.

Author  Topic 

This_guy_needs_help
Starting Member

1 Post

Posted - 2013-08-31 : 11:36:49
Hi everyone,
I know this has been probably been asked before but this has a little twist to it...
I'm generating a random number to create an Order Number in C#, and I need to check if there is a duplicate Order Number in my sql table, but what I need to do ( I have figured this out before but lost my code ) that if it does find a duplicate number that I need it to return an output of 1 and if there is no duplicate order number I need it to return a 0 so I can handle it in my code.
I have figured this out ages ago but I can't find my code anywhere for it and am stuck trying to figure it out again.

Thanks everyone for helping me with this.

Sincerely,
This_guy_needs_help

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-08-31 : 15:21:16
SELECT COUNT(*)
FROM (
select number from dbo.table1
intersect
select @parameter
) AS d



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-02 : 09:04:19
why do you need to generate it at application layer? why not just make it identity in database so that its gets generated automatically?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -