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
 General SQL Server Forums
 New to SQL Server Programming
 SQL UPDATE

Author  Topic 

skumar
Starting Member

10 Posts

Posted - 2006-08-23 : 10:46:22
Hi guys,

i'm a newbie in database and i need some ideas for the below mentioned
problem.

i'm creating sql table from a txt file using DTS package, now once the table
gets created, i need to multiple some revenue accounts with xyz number and
expense accounts with abc number.

i'm thinking more towards the line of writing a store procedure but don't
have any experience in it.

PLease guide me in the right direction, also if a good book could be refered
for future; which will help me query language and this kind of issues, that
will be GREAT!!

Thanx in advance

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-23 : 10:50:37
U can use an update statement to Update a table.
If u give some sample data & expected results, v may be able to help u.
Its good to have a Stored Proc. if u this is not a "One Time" task.

For language references:
U can use BOL (books online - ie. the help file of SQL server - u get by hitting F1 key when in Query Analyzer)

Srinika
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-23 : 10:51:14
SQL Book online is the best book..

refers to this sites.

http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp

Chirag
Go to Top of Page

skumar
Starting Member

10 Posts

Posted - 2006-08-23 : 11:01:13
thanx for the quick response guys,
here is a lil example of what i have and what i wanna do....

prd. dep. account jan feb mar
100 121 110-123 100 200 300
101 121 110-124 101 201 301
101 121 520-500 230 234 898
101 121 750-564 999 777 898

now considering that accounts that starts with 110* are expense and data for jan feb and mar needs to be multiplied by 10 and accounts starting with 520* are revenue needs to be multiplied by 50. and 750* accounts multiplied by 5

this will be for every few weeks drill, so need something that could be automated or scheduled..

PLease advice.. thanx

Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-23 : 11:05:53
I'll give u one, u do the rest

Update urTable set jan = jan * 10, feb = feb * 10, .... where left(account,3) = '110'

Srinika
Go to Top of Page

skumar
Starting Member

10 Posts

Posted - 2006-08-23 : 13:27:10
Thanx Srinika,
this will do, i'll take care of the rest!!!!

Please be easy on me but, how can we automate this query or schedule it to run whenever we want rather than manually launch it.

Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-23 : 14:17:12
If u automate, this will become somewhat exploding.
if automated : u multiply data in a column by 10, again by 10 again by 10 ....
May be u need to update only newly added stuff. If so u may need to deal with that accordingly.

if still u need automation, u may create a DTS package & schedule it

Srinika
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-24 : 02:24:29
How About using Case ??

Update urTable set jan = Case
When left(account,3) = '110' Then jan * 10
When left(account,3) = '520' Then jan *50
When left(account,3) = '750' Then jan * 5 End
... so on for feb..



Chirag
Go to Top of Page
   

- Advertisement -