I have a Sales tax column in one of my SQL Table where Data is stored.
I was wondering is it possible to place an constraint on the table itself for the Sales Tax
Column saying ” if > June 2008 tax is 2 % ” else “tax is 4 %”?
Should that come from stored procs related to that Table?
If you want to make sure that the column ‘tax’ is 2 or 4 depending on the month (e.g., month 9 = September), then you could do this:
Obviously, vary for your conditions. e.g., to test for dates after June 2008, it’s a bit simpler.
You should be able to build this into a CHECK constraint of using a similar mechanism as I’ve dropped in the first example.
Note this only checks the value that put in to the table. It won’t auto-populate. As other people have noted, if you want auto-population, you need a trigger.