English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

DECLARE @totalDue money
DECLARE @totalDue1 money
DECLARE @totalDue2 money
set @totalDue=(select sum(balance) from Chart_Of_Accounts
where account like '11%'and [ShortDescription]like 'La Jolla%'
group by [ShortDescription])
set @totalDue1=(select sum (balance) from Chart_Of_Accounts
where account like '11%'and [ShortDescription]='Del Mar'group by [ShortDescription])
set @totalDue2=(select sum (balance) from Chart_Of_Accounts
where account like '11%'and [ShortDescription]='Encinitas'group by [ShortDescription])
print 'The Total Balance for La Jolla is: $' + convert(varchar, @totalDue,1)
print ' '
print 'The Total Balance for Delmar is: $' + convert(varchar, @totalDue1,1)
print ' '
print 'The Total Balance for Encinitas is: $' + convert(varchar, @totalDue2,1)
print ' '
DECLARE @thisOne money
set @thisOne=(select sum(balance) from Chart_Of_Accounts
where account like '12%')
print 'The Inventory balances for La Jolla are as follows: $'+ convert(varchar,@thisOne,1)

2007-01-12 04:04:38 · 2 answers · asked by Valencia E 1 in Computers & Internet Programming & Design

2 answers

Here's my try:

Line 1 to 3- Declaring variables totaldue, totaldue1 and totaldue2 as "money" data type.

Line 4-6: Get me the "total balance from Chart of accounts table where account starts with 11 as prefix (it will fetch all accounts like 111, 11222, 11323 and not 2111) and short description starting with prefix "la jolla"(it will fetch all short description like "la jolladdd", "la jollah hiw" and not "a la jolla"). "Group by" sql is used cuz u will certainly have more than one rows for short description "la jolla%". The database will group all la jolla rows and u will get the sum.

Then u are setting the above retrieved sum to variable "totaldue"

Line 7-8: Same as above

Line 9-10: same as above

Line 11-16: u are printing variable values on Sql client, converting them to string datatype first.

Line 17:
Declaring variable "thisone" as "money" datatype.

Line 18-19: Get me total balance from Chart of Accnts table where account starts with "12"(it will fetch all accounts 12, 1245, 12545 and not 3212). Assign total balance to variable "thisone"

Line 20: Printing the variable "thisone" converting it to string first.

"

Best wishes :)

2007-01-12 04:24:50 · answer #1 · answered by rony d 2 · 0 0

totalDue will be the total of the balance column in the Chart_Of_Accounts table, where the account column begins with 11 and the ShortDescription column begins with La Jolla.

totalDue1 will be the total of the balance column in the Chart_Of_Accounts table, where the account column begins with 11 and the ShortDescription column begins with Del Mar.

totalDue2 will be the total of the balance column in the Chart_Of_Accounts table, where the account column begins with 11 and the ShortDescription column begins with Encinitas.

The three values you got are then printed. Because you are printing this to the screen, you need to convert the totalDue variables from money to varchar.

thisOne is the total of the balance column in the Chart_Of_Accounts table, where the account column begins with 12.

That variable is then printed to the screen.

2007-01-12 12:54:10 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers