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.
Author |
Topic |
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2014-12-18 : 11:05:10
|
I am using teh below if condition, can you please provide the correct way of handling below criteria.@ContractID is a varchar(70) text valuedeclare @CountCTR as bitset @CountCTR = (select top 1 contractno from TAB_Contracts where contractno = @ContractID)If @CountCTR <> true BEGIN will run an Insert query ENDThanks a lot for the helpful info. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-12-18 : 15:28:55
|
Are you trying to insert if there is no row in the TAB_Contracts table where contractno column is equal to the value of @ContractID? If soIF NOT EXISTS( SELECT * FROM TAB_Contracts WHERE contractno = @ContractID )BEGIN -- insert query hereEND |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-18 : 15:47:27
|
OR:insert into ...select ...stuff to insertwhere not exists ( select 1 from TAB_Contracts where contractno = @ContractID ) |
|
|
|
|
|