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 2005 Forums
 Transact-SQL (2005)
 Please give me solution to my problem asap

Author  Topic 

swathigardas
Posting Yak Master

149 Posts

Posted - 2007-09-12 : 06:57:57
Hi all. I’ve been visiting this forum... But this is my first time posting a question.

I’m using Sql 2005 as database.
Let me explain you the problem
There are tables like Price_table_10, Price_table_15, Price_Table_63, Price_Table_100, Price_Table_250

Same column Format is Present in all the Tables
Table for Price_table_for_10 looks like these

Volt Guarntee_year Price Tax Total Price
10 0 12000
10 1 13000
10 2 24777
10 3 5688
10 4 89000
10 5 43567
10 6 7889
10 7 8754
10 8 9024


Now the same format is applied all the tables.
Tax is updated based on the Guarantee Year
For the Guarantee Year 0
The query is
Update Price_table_10 set tax=price*(11/100) where Guarantee Year=0
So its different for all the Guarantee Years

The percentage used for tax calculation is different for different Price tables

I want to update all these Price tables in a if loop.

The loop should be something like

If Price_table_10
Then update Price_table_10 set tax = price*(11/100) where Guarantee Year=0
If Price_table_15
then update Price_table_25 set tax=price*(13/100) where Guarantee Year=0
If Price_table_25
then update Price_table_15 set tax=price*(15/100) where Guarantee Year=0






DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2007-09-12 : 06:59:20
Instant solution: Read my signature, follow the LEARN SQL links. Problem solved.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2007-09-12 : 07:07:13
use dsql to pull this off, passing the table name
check out cursor or while loop

also, you should really have your application handle this update when the record gets inserted... makes life easier

--------------------
keeping it simple...
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-12 : 07:43:05
One thing not mentioned in those links are INTEGER DIVISION.

11 / 100 equal 0!
Write 11 / 100.0 instead.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-09-12 : 10:21:54
what's the matter Peso? do you like paying tax?




elsasoft.org
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-12 : 11:02:43
Hehehe... No, but if you do not pay tax in Sweden, you are most likely to go to prison.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Jenda
Starting Member

29 Posts

Posted - 2007-09-12 : 14:28:16
quote:
Originally posted by swathigardas

Hi all. I’ve been visiting this forum... But this is my first time posting a question.

I’m using Sql 2005 as database.
Let me explain you the problem
There are tables like cost_table_10, Cost_table_15, Cost_Table_63, Cost_Table_100, Cost_Table_250


Step 1. Shoot whoever designed the database schema.
Step 2. Consolidate all Cost_Table_x into a single Cost_Table and (to localize the impact of the change) create a view in place of every Cost_Table_x.
Step 3. run the query using CASE WHEN... THEN ... END to compute the tax with the right constants for each former table
Step 4. Go home

P.S.: Don't forget to get rid of the body!
Go to Top of Page

wackoyacky
Starting Member

25 Posts

Posted - 2007-09-13 : 05:25:53
Just my two cents...

You should have ask help in a nicer way, not like as if you're paying someone to solve your problem and what makes things worst is you want it ASAP! lolz

Go to Top of Page

swathigardas
Posting Yak Master

149 Posts

Posted - 2007-09-14 : 05:26:11
Hey thanks Jenda

i guess i can work with the solution that you provided me.

regards

swathi
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-14 : 05:44:09
quote:
Originally posted by Peso

Hehehe... No, but if you do not pay tax in Sweden, you are most likely to go to prison.



E 12°55'05.25"
N 56°04'39.16"



50% tax?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-09-14 : 07:54:44
taxes in Sweden are so high, even after the integer division bug they are still non-zero.




elsasoft.org
Go to Top of Page
   

- Advertisement -