Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic SQL help

Status
Not open for further replies.

draissam

MIS
Oct 15, 2003
27
US
Hi all,

I have two questions regarding running a select statement.

1-I have a table with two columns: dr_amount and cr_amount. When the amount is negative, dr_amount is populated, and when it is positive, cr_amount is populated.
I am running a statement that should extract the amount, positive or negative, and populate one field amount. How can I do that with SQL?

2- I have a table1 with two columns: New_code and description (text field). In table 2, I have these columns: Old_code and description. I neeed to map the old code to the new code. How can I do it with SQL.

Thanks for your help.

OF11i!
 
1. You can't have negative debits/credits?
Where is the amount field you want to populate.
Does this table really have two columns? Does it have more than one row?

2. Good question.
Maybe select t1.new_code, t2.new_code from t1 join t2 on t1.description = t2.description
You'll have to give more info 0- is that what you want to do? Are descriptions unique?


======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
nigelrivett, thanks for your reply.
1- I don't know what you mean by "you can't have negative ..." but what I have is the following:
A table with two columns, one called dr_amount, and the other one cr_amount. All the negative figures are put in dr_amount (cr_amount have 0), and all the positive figures are put in cr_amount (dr_amount have 0).
Because I don't want to have two amount columns in a report I am generating, I am trying to merge the two amount columns in one.

2-I will try your suugestion, and the description should be usinque otherwise I wouldn't be able to join the two tables.

Cheers!

OF11i!
 
create a column in the table...

update table
set newcolumnname = isnull(cr_amount,0) + isnull(dr_amount,0)

then drop the two columns that are not needed anymore

dlc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top