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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Exists function...help!

Author  Topic 

brendalisalowe
Constraint Violating Yak Guru

269 Posts

Posted - 2004-08-11 : 12:32:08
I need a statement that checks to see if a case doesn't exist, and if it doesn', I want to insert it into another table. This is what I have, but it doesn't work:

IF NOT EXISTS(SELECT * from tblForeverHUDdata WHERE CaseNumber = '" & HUDCaseNumber & "') INSERT * INTO tblForeverHUDdata FROM tblHUDdata

Any ideas? Thanks!

Brenda

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2004-08-11 : 12:35:48
[code]IF(NOT EXISTS(SELECT * from tblForeverHUDdata WHERE CaseNumber = '" & HUDCaseNumber & "'))
BEGIN
INSERT INSERT * INTO tblForeverHUDdata FROM tblHUDdata
END[/code]

Dustin Michaels
Go to Top of Page

brendalisalowe
Constraint Violating Yak Guru

269 Posts

Posted - 2004-08-11 : 12:43:32
It doesn't like that. It says there is something wrong with *. What would it be?

Brenda
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-11 : 12:54:12
if the tblForeverHUDdata already exists in your db, you must use
insert into tblForeverHUDdata(col1, ..., coln)
select col1, ..., coln

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

brendalisalowe
Constraint Violating Yak Guru

269 Posts

Posted - 2004-08-11 : 13:05:36
Thanks! Works now!

Brenda
Go to Top of Page
   

- Advertisement -