dbTalk Databases Forums  

help on query

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss help on query in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
B
 
Posts: n/a

Default help on query - 04-08-2005 , 09:19 PM






I need advice on how to approach this. To simplify with a sample, below is a
list of various calculations based from ITEMS table:
ITEM_NO FIELD_CALCULATION
123 cost*qty
111 cost-discount
222 sales*discount
333 cost-freight
etc...
There are 20 additional line items with different calculations.

From my SP, how do I incorporate the above to say:
SELECT ??
INTO #tmp1
FROM GL_ACCOUNT GL,
ITEMS I
WHERE GL.ITEM_NO = I.ITEM_NO

TIA!
Bob






Reply With Quote
  #2  
Old   
John Bell
 
Posts: n/a

Default Re: help on query - 04-09-2005 , 03:08 AM






Hi

You could try something like:

SELECT I.Item_No,
CASE I.Item_No WHEN 123 THEN GL.cost*GL.qty
WHEN 111 THEN GL.cost-GL.discount
WHEN 222 THEN GL.sales*GL.discount
WHEN 333 THEN GL.cost-GL.freight
END AS [Calculation]
FROM GL_ACCOUNT GL,
JOIN ITEMS I ON GL.ITEM_NO = I.ITEM_NO

John

"B" <no_spam (AT) no_spam (DOT) com> wrote

Quote:
I need advice on how to approach this. To simplify with a sample, below is
a
list of various calculations based from ITEMS table:
ITEM_NO FIELD_CALCULATION
123 cost*qty
111 cost-discount
222 sales*discount
333 cost-freight
etc...
There are 20 additional line items with different calculations.

From my SP, how do I incorporate the above to say:
SELECT ??
INTO #tmp1
FROM GL_ACCOUNT GL,
ITEMS I
WHERE GL.ITEM_NO = I.ITEM_NO

TIA!
Bob








Reply With Quote
  #3  
Old   
B
 
Posts: n/a

Default Re: help on query - 04-09-2005 , 06:02 AM



I was hoping to use the table created as a source without having to hardcode
since it will be used by other SP.

Thank you for your time.

"John Bell" <jbellnewsposts (AT) hotmail (DOT) com> wrote

Quote:
Hi

You could try something like:

SELECT I.Item_No,
CASE I.Item_No WHEN 123 THEN GL.cost*GL.qty
WHEN 111 THEN GL.cost-GL.discount
WHEN 222 THEN GL.sales*GL.discount
WHEN 333 THEN GL.cost-GL.freight
END AS [Calculation]
FROM GL_ACCOUNT GL,
JOIN ITEMS I ON GL.ITEM_NO = I.ITEM_NO

John

"B" <no_spam (AT) no_spam (DOT) com> wrote in message
news:ZrydnROKGqA3psrfRVn-uQ (AT) rcn (DOT) net...
I need advice on how to approach this. To simplify with a sample, below
is
a
list of various calculations based from ITEMS table:
ITEM_NO FIELD_CALCULATION
123 cost*qty
111 cost-discount
222 sales*discount
333 cost-freight
etc...
There are 20 additional line items with different calculations.

From my SP, how do I incorporate the above to say:
SELECT ??
INTO #tmp1
FROM GL_ACCOUNT GL,
ITEMS I
WHERE GL.ITEM_NO = I.ITEM_NO

TIA!
Bob










Reply With Quote
  #4  
Old   
John Bell
 
Posts: n/a

Default Re: help on query - 04-09-2005 , 08:02 AM



Hi

Creating a view would overcome that problem.

John

"B" <no_spam (AT) no_spam (DOT) com> wrote

Quote:
I was hoping to use the table created as a source without having to
hardcode
since it will be used by other SP.

Thank you for your time.

"John Bell" <jbellnewsposts (AT) hotmail (DOT) com> wrote in message
news:42578d55$0$26738$db0fefd9 (AT) news (DOT) zen.co.uk...
Hi

You could try something like:

SELECT I.Item_No,
CASE I.Item_No WHEN 123 THEN GL.cost*GL.qty
WHEN 111 THEN GL.cost-GL.discount
WHEN 222 THEN GL.sales*GL.discount
WHEN 333 THEN GL.cost-GL.freight
END AS [Calculation]
FROM GL_ACCOUNT GL,
JOIN ITEMS I ON GL.ITEM_NO = I.ITEM_NO

John

"B" <no_spam (AT) no_spam (DOT) com> wrote in message
news:ZrydnROKGqA3psrfRVn-uQ (AT) rcn (DOT) net...
I need advice on how to approach this. To simplify with a sample, below
is
a
list of various calculations based from ITEMS table:
ITEM_NO FIELD_CALCULATION
123 cost*qty
111 cost-discount
222 sales*discount
333 cost-freight
etc...
There are 20 additional line items with different calculations.

From my SP, how do I incorporate the above to say:
SELECT ??
INTO #tmp1
FROM GL_ACCOUNT GL,
ITEMS I
WHERE GL.ITEM_NO = I.ITEM_NO

TIA!
Bob












Reply With Quote
  #5  
Old   
--CELKO--
 
Posts: n/a

Default Re: help on query - 04-09-2005 , 09:15 PM



Have you ever had a software engineering course? Probably not, because
this approach is a violaiton of the principle of cohesion and it
confuses data and code.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.