Please start any new threads on our new site at http://forums.sqlteam.com. 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!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help looking for duplicates, with a twist.
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

This_guy_needs_help
Starting Member

1 Posts

Posted - 08/31/2013 :  11:36:49  Show Profile  Reply with Quote
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

Sweden
30421 Posts

Posted - 08/31/2013 :  15:21:16  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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

India
52326 Posts

Posted - 09/02/2013 :  09:04:19  Show Profile  Reply with Quote
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
  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.03 seconds. Powered By: Snitz Forums 2000