SQL Server Forums
Profile | Register | 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
 Insert record only if record does not already exis
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

eirikr_1
Starting Member

26 Posts

Posted - 02/11/2013 :  14:39:00  Show Profile  Reply with Quote
what is wrong with this sql? It does not allow me to insert a test computer, when test is not in database

if not exists (select distinct NetBIOSName from Computers)
begin
insert into Computers(NetBIOSName, IP)
values('test','111.22.33.444')
end

eirikr_1
Starting Member

26 Posts

Posted - 02/11/2013 :  14:48:08  Show Profile  Reply with Quote
I got it. I missed a condition in
select distinct NetBIOSName from Computers where NetBIOSName='test'
Go to Top of Page

DonAtWork
Flowing Fount of Yak Knowledge

2161 Posts

Posted - 02/11/2013 :  14:48:18  Show Profile  Reply with Quote
Unless your table is empty, select distinct NetBIOSName from Computers will always return at least one record.


[Edit]
NM you found it.




How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Edited by - DonAtWork on 02/11/2013 14:49:49
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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