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 |
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2010-01-05 : 16:20:11
|
| What is the best solution to implement if I i don't want the column to be inserted to same value? Once I find the value I want to disable this alert and insert the value manually.example"col16.33.4insert col1select 6.3 this is raise an error message that tells me i have this value already in the column. Then once i read the msg. I can manually disable the trigger or whaterver i implemented and insert the value manually.any ideas? trigger is the best solution? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2010-01-05 : 19:59:07
|
| declare @receiptBal money, @receiptdate datetime, @receiptID intset @receiptBal = '8.46'set @receiptdate = '20091202'-- select * from receipts where receiptdate is null and receiptBal = @receiptBalif exists (select 1 from receipts where receiptBal = @receiptBal and receiptdate is null )begin update receipts set receiptdate = @receiptdate where receiptBal = @receiptBal and receiptdate is null print 'date updated'endelsebegin insert receipts (receiptBal, StoreID, receiptDate) select @receiptBal, 8, @receiptdate print 'inserted'endselect * from receipts where receiptBal = @receiptBalOk I implemented your way. After the receiptdate column is updated I run this procedure again and it inserts a new value. How could I stop that? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-01-06 : 02:06:26
|
| declare @receiptBal money, @receiptdate datetime, @receiptID intset @receiptBal = '8.46'set @receiptdate = '20091202'-- select * from receipts where receiptdate is null and receiptBal = @receiptBalif exists (select 1 from receipts where receiptBal = @receiptBal and receiptdate is null )begin update receiptsset receiptdate = @receiptdatewhere receiptBal = @receiptBaland receiptdate is nullprint 'date updated'endif not exists (select 1 from receipts where receiptBal = @receiptBal and receiptdate=@receiptdate)begininsert receipts (receiptBal, StoreID, receiptDate)select @receiptBal, 8, @receiptdateprint 'inserted'endselect * from receipts where receiptBal = @receiptBalMadhivananFailing to plan is Planning to fail |
 |
|
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2010-01-06 : 03:20:00
|
| Madhi,Thanks that did the job. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-01-06 : 03:26:08
|
quote: Originally posted by basicconfiguration Madhi,Thanks that did the job.
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|