dbTalk Databases Forums  

Sql Query Needed

microsoft.public.sqlserver.tools microsoft.public.sqlserver.tools


Discuss Sql Query Needed in the microsoft.public.sqlserver.tools forum.



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

Default Sql Query Needed - 06-04-2004 , 02:11 PM






I have a table with the following information

col1, col2, part, desc, cost, retail, quant.

The destination table has the following:

id, part, desc, retail, sale, quant, cost, col1 and col2

What I need to do is update or add to the destination table with the
following info.

Where Retail > 10.00 and col1 = P then Sale = 0.00
Where quant is not null then Sale = 0.00
Where the Greater of (cost * 1.2) or (retail * .8) = sale
then the rest of the data is a stright copy.

How can I do this in one query?

Dennis




Reply With Quote
  #2  
Old   
Eric.Li
 
Posts: n/a

Default Re: Sql Query Needed - 06-04-2004 , 02:26 PM






it's gonna be something like this

select sales = if((retail > 10 and col1 = P) or (quant is not null),
sales=0, if((cost * 1.2) > (retail *.8), cost * 1.2, retail * 0.8)



--
Eric Li
SQL DBA
MCDBA

Dennis Burgess wrote:

Quote:
I have a table with the following information

col1, col2, part, desc, cost, retail, quant.

The destination table has the following:

id, part, desc, retail, sale, quant, cost, col1 and col2

What I need to do is update or add to the destination table with the
following info.

Where Retail > 10.00 and col1 = P then Sale = 0.00
Where quant is not null then Sale = 0.00
Where the Greater of (cost * 1.2) or (retail * .8) = sale
then the rest of the data is a stright copy.

How can I do this in one query?

Dennis




Reply With Quote
  #3  
Old   
Dennis Burgess
 
Posts: n/a

Default Re: Sql Query Needed - 06-04-2004 , 02:36 PM



Thank you very much.. Let me get this stright.

So we are selecting if retal is less than 10, and col1 = P. I see that. Or
if quantiy is not nuall. Then sales =0 K.

I don't see how it is selecting the greater of the two. Maye I am not
reading it right ..

Again, thank you VERY VERY much!

Dennis

"Eric.Li" <anonymous (AT) microsoftnews (DOT) org> wrote

Quote:
it's gonna be something like this

select sales = if((retail > 10 and col1 = P) or (quant is not null),
sales=0, if((cost * 1.2) > (retail *.8), cost * 1.2, retail * 0.8)



--
Eric Li
SQL DBA
MCDBA

Dennis Burgess wrote:

I have a table with the following information

col1, col2, part, desc, cost, retail, quant.

The destination table has the following:

id, part, desc, retail, sale, quant, cost, col1 and col2

What I need to do is update or add to the destination table with the
following info.

Where Retail > 10.00 and col1 = P then Sale = 0.00
Where quant is not null then Sale = 0.00
Where the Greater of (cost * 1.2) or (retail * .8) = sale
then the rest of the data is a stright copy.

How can I do this in one query?

Dennis






Reply With Quote
  #4  
Old   
Eric.Li
 
Posts: n/a

Default Re: Sql Query Needed - 06-04-2004 , 02:45 PM



The if clause works like this

if (condition, return this if condition is true, return this if
condition is faluse)

in your case, sales = 0 if retail > 0 and col1 = P or quant is not null,
if this condition is true, then sales = 0, otherwise, it goes to the
second if statement, which test if cost * 1.2 > retail * 0.8, if true,
then it returns cost * 1.2, otherwise retail * 0.8.

hope it makes sense to you

--
Eric Li
SQL DBA
MCDBA

Dennis Burgess wrote:

Quote:
Thank you very much.. Let me get this stright.

So we are selecting if retal is less than 10, and col1 = P. I see that. Or
if quantiy is not nuall. Then sales =0 K.

I don't see how it is selecting the greater of the two. Maye I am not
reading it right ..

Again, thank you VERY VERY much!

Dennis

"Eric.Li" <anonymous (AT) microsoftnews (DOT) org> wrote in message
news:O24RCnmSEHA.1168 (AT) TK2MSFTNGP11 (DOT) phx.gbl...

it's gonna be something like this

select sales = if((retail > 10 and col1 = P) or (quant is not null),
sales=0, if((cost * 1.2) > (retail *.8), cost * 1.2, retail * 0.8)



--
Eric Li
SQL DBA
MCDBA

Dennis Burgess wrote:


I have a table with the following information

col1, col2, part, desc, cost, retail, quant.

The destination table has the following:

id, part, desc, retail, sale, quant, cost, col1 and col2

What I need to do is update or add to the destination table with the
following info.

Where Retail > 10.00 and col1 = P then Sale = 0.00
Where quant is not null then Sale = 0.00
Where the Greater of (cost * 1.2) or (retail * .8) = sale
then the rest of the data is a stright copy.

How can I do this in one query?

Dennis








Reply With Quote
  #5  
Old   
Dennis Burgess
 
Posts: n/a

Default Re: Sql Query Needed - 06-04-2004 , 02:49 PM



AHHHHHHHHHHHHHHHHHHHHHH

And belive me, I did say that out loud! ha ha. .

Thank you VERY MUCH!

Dennis

"Eric.Li" <anonymous (AT) microsoftnews (DOT) org> wrote

Quote:
The if clause works like this

if (condition, return this if condition is true, return this if
condition is faluse)

in your case, sales = 0 if retail > 0 and col1 = P or quant is not null,
if this condition is true, then sales = 0, otherwise, it goes to the
second if statement, which test if cost * 1.2 > retail * 0.8, if true,
then it returns cost * 1.2, otherwise retail * 0.8.

hope it makes sense to you

--
Eric Li
SQL DBA
MCDBA

Dennis Burgess wrote:

Thank you very much.. Let me get this stright.

So we are selecting if retal is less than 10, and col1 = P. I see that.
Or
if quantiy is not nuall. Then sales =0 K.

I don't see how it is selecting the greater of the two. Maye I am not
reading it right ..

Again, thank you VERY VERY much!

Dennis

"Eric.Li" <anonymous (AT) microsoftnews (DOT) org> wrote in message
news:O24RCnmSEHA.1168 (AT) TK2MSFTNGP11 (DOT) phx.gbl...

it's gonna be something like this

select sales = if((retail > 10 and col1 = P) or (quant is not null),
sales=0, if((cost * 1.2) > (retail *.8), cost * 1.2, retail * 0.8)



--
Eric Li
SQL DBA
MCDBA

Dennis Burgess wrote:


I have a table with the following information

col1, col2, part, desc, cost, retail, quant.

The destination table has the following:

id, part, desc, retail, sale, quant, cost, col1 and col2

What I need to do is update or add to the destination table with the
following info.

Where Retail > 10.00 and col1 = P then Sale = 0.00
Where quant is not null then Sale = 0.00
Where the Greater of (cost * 1.2) or (retail * .8) = sale
then the rest of the data is a stright copy.

How can I do this in one query?

Dennis










Reply With Quote
  #6  
Old   
Eric.Li
 
Posts: n/a

Default Re: Sql Query Needed - 06-04-2004 , 02:53 PM



Oops, not if, should be case clause

also, you should check the BOL on case, if you directly copy my code,
you will get syntax error


oh well, let me just write it out for you


select sales =
case when (retail > 10 and col1 = P) or (quant is not null)
then
sales=0
else
case when (cost * 1.2) > (retail *.8)
then
cost * 1.2
else
retail * 0.8
end
end

hope I didn't mess up, but you know, it's Friday afternoon, I can't
think straight Friday after 12

--
Eric Li
SQL DBA
MCDBA

Eric.Li wrote:

Quote:
The if clause works like this

if (condition, return this if condition is true, return this if
condition is faluse)

in your case, sales = 0 if retail > 0 and col1 = P or quant is not null,
if this condition is true, then sales = 0, otherwise, it goes to the
second if statement, which test if cost * 1.2 > retail * 0.8, if true,
then it returns cost * 1.2, otherwise retail * 0.8.

hope it makes sense to you


Reply With Quote
  #7  
Old   
Dennis Burgess
 
Posts: n/a

Default Re: Sql Query Needed - 06-08-2004 , 11:07 AM



ARG.. nothen. I can't get this to work..


"Eric.Li" <anonymous (AT) microsoftnews (DOT) org> wrote

Quote:
Oops, not if, should be case clause

also, you should check the BOL on case, if you directly copy my code,
you will get syntax error


oh well, let me just write it out for you


select sales =
case when (retail > 10 and col1 = P) or (quant is not null)
then
sales=0
else
case when (cost * 1.2) > (retail *.8)
then
cost * 1.2
else
retail * 0.8
end
end

hope I didn't mess up, but you know, it's Friday afternoon, I can't
think straight Friday after 12

--
Eric Li
SQL DBA
MCDBA

Eric.Li wrote:

The if clause works like this

if (condition, return this if condition is true, return this if
condition is faluse)

in your case, sales = 0 if retail > 0 and col1 = P or quant is not null,
if this condition is true, then sales = 0, otherwise, it goes to the
second if statement, which test if cost * 1.2 > retail * 0.8, if true,
then it returns cost * 1.2, otherwise retail * 0.8.

hope it makes sense to you




Reply With Quote
  #8  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Sql Query Needed - 06-08-2004 , 05:28 PM



On Tue, 8 Jun 2004 11:07:15 -0500, Dennis Burgess wrote:

Quote:
ARG.. nothen. I can't get this to work..
Hi Dennis,

You don't say what goes wrong. Am I guessing correct that SQL Server finds
the syntax to be incorrect near '='?

I think that Eric accidentally typed one 'sales=' too many.


select sales =
case when (retail > 10 and col1 = P) or (quant is not null)
then
0 -- <== This line is changed!!!
else
case when (cost * 1.2) > (retail *.8)
then
cost * 1.2
else
retail * 0.8
end
end

(untested)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


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.