- Moderator
- #1
Let me start by saying I hate tax law.
I have a table that has cities in MN with their tax rates.
I also have to look up for Wisconsin.
So, here's the scenario:
If the State is MN, and the city is in the table, then it needs to return the tax amount.
If the state is MN, and the city is NOT in the table, it needs to return 6.875
Then it needs to do the same thing for wisconsin.
I'm having a hard time nesting the statements properly....
This is the (non-working) code that I have:
I haven't fleshed out the Wisconsin part yet, because I'm evidently having syntax issues.... but the Wisconsin area will have to be essentially the same as the MN area.
Any thoughts?
Thanks in advance!
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg
I have a table that has cities in MN with their tax rates.
I also have to look up for Wisconsin.
So, here's the scenario:
If the State is MN, and the city is in the table, then it needs to return the tax amount.
If the state is MN, and the city is NOT in the table, it needs to return 6.875
Then it needs to do the same thing for wisconsin.
I'm having a hard time nesting the statements properly....
This is the (non-working) code that I have:
Code:
IF ( @State = 'MN')
BEGIN
IF EXISTS (SELECT * FROM tbl_Tax WHERE lower([City]) like lower(@CityName) AND lower([State]) like (@State)))
SELECT [TaxRate] FROM tbl_Tax WHERE lower([City]) like lower(@CityName) AND lower([State]) like (@State)
ELSE
SELECT '6.875' AS [TaxRate]
END
ELSE IF ( @State = 'WI')
BEGIN
SELECT '5.6' AS [TaxRate]
END
I haven't fleshed out the Wisconsin part yet, because I'm evidently having syntax issues.... but the Wisconsin area will have to be essentially the same as the MN area.
Any thoughts?
Thanks in advance!
Just my 2¢
"What the captain doesn't realize is that we've secretly replaced his Dilithium Crystals with new Folger's Crystals."
--Greg