dbTalk Databases Forums  

Select Help

sybase.public.sqlanywhere.general sybase.public.sqlanywhere.general


Discuss Select Help in the sybase.public.sqlanywhere.general forum.



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

Default Select Help - 12-15-2003 , 10:37 AM






I have the following table and I need to select the rows for a specific
SiteCode, ProductCode. But I only need the rows with the current price. ie
MAX(EffectiveDate) for dates <= NOW()

SELECT * FROM Product2PriceGroup
WHERE SiteCode = '24'
AND ProductCode = '8'
AND EffectiveDate = What can I put here to select only rows with the current
price?

CREATE TABLE "DBA"."Product2PriceGroup" (
"SiteCode" CHAR(10) NOT NULL,
"ProductCode" CHAR(10) NOT NULL,
"PriceGroupCode" CHAR(10) NOT NULL,
"PriceType" CHAR(1) NOT NULL DEFAULT 'T'
CHECK(@COLUMN IN ('T','M','P','L','Q','Y','C')),
"EffectiveDate" DATE NOT NULL,
"Price" DECIMAL(11,4) NOT NULL,
"MinimumCharge" DECIMAL(11,4) NOT NULL,
PRIMARY KEY CLUSTERED ("SiteCode", "ProductCode", "PriceGroupCode",
"PriceType", "EffectiveDate")
);


TIA

Eddie Sizemore



Reply With Quote
  #2  
Old   
David Kerber
 
Posts: n/a

Default Re: Select Help - 12-15-2003 , 12:12 PM






In article <3fdde361$1@forums-1-dub>, esizemorenospam (AT) qx (DOT) net says...
Quote:
I have the following table and I need to select the rows for a specific
SiteCode, ProductCode. But I only need the rows with the current price. ie
MAX(EffectiveDate) for dates <= NOW()

SELECT * FROM Product2PriceGroup
WHERE SiteCode = '24'
AND ProductCode = '8'
AND EffectiveDate = What can I put here to select only rows with the current
price?
How about:

.... AND EffectiveDate = (select max(effectivedate) from
Product2PriceGroup where SiteCode= '24' and ProductCode = '8')


Quote:
CREATE TABLE "DBA"."Product2PriceGroup" (
"SiteCode" CHAR(10) NOT NULL,
"ProductCode" CHAR(10) NOT NULL,
"PriceGroupCode" CHAR(10) NOT NULL,
"PriceType" CHAR(1) NOT NULL DEFAULT 'T'
CHECK(@COLUMN IN ('T','M','P','L','Q','Y','C')),
"EffectiveDate" DATE NOT NULL,
"Price" DECIMAL(11,4) NOT NULL,
"MinimumCharge" DECIMAL(11,4) NOT NULL,
PRIMARY KEY CLUSTERED ("SiteCode", "ProductCode", "PriceGroupCode",
"PriceType", "EffectiveDate")
);


TIA

Eddie Sizemore




Reply With Quote
  #3  
Old   
Eddie Sizemore
 
Posts: n/a

Default Re: Select Help - 12-15-2003 , 01:11 PM



Thanks, the following ended up working. I just had to extend it to include
all the columns of the pk then limit the future prices.


SELECT * FROM Product2PriceGroup as p1
WHERE SiteCode = '24'
AND ProductCode = '8'
AND EffectiveDate = (select max(effectivedate) from Product2PriceGroup as
p2
where p1.SiteCode = p2.SiteCode
and p1.ProductCode = p2.ProductCode
and p1.PriceGroupCode = p2.PriceGroupCode
and p1.pricetype = p2.pricetype
and p2.effectivedate <= date(now()))


"David Kerber" <ns_dkerber (AT) ns_wraenviro (DOT) com> wrote

Quote:
In article <3fdde361$1@forums-1-dub>, esizemorenospam (AT) qx (DOT) net says...
I have the following table and I need to select the rows for a specific
SiteCode, ProductCode. But I only need the rows with the current price.
ie
MAX(EffectiveDate) for dates <= NOW()

SELECT * FROM Product2PriceGroup
WHERE SiteCode = '24'
AND ProductCode = '8'
AND EffectiveDate = What can I put here to select only rows with the
current
price?

How about:

... AND EffectiveDate = (select max(effectivedate) from
Product2PriceGroup where SiteCode= '24' and ProductCode = '8')



CREATE TABLE "DBA"."Product2PriceGroup" (
"SiteCode" CHAR(10) NOT NULL,
"ProductCode" CHAR(10) NOT NULL,
"PriceGroupCode" CHAR(10) NOT NULL,
"PriceType" CHAR(1) NOT NULL DEFAULT
'T'
CHECK(@COLUMN IN ('T','M','P','L','Q','Y','C')),
"EffectiveDate" DATE NOT NULL,
"Price" DECIMAL(11,4) NOT
NULL,
"MinimumCharge" DECIMAL(11,4) NOT NULL,
PRIMARY KEY CLUSTERED ("SiteCode", "ProductCode", "PriceGroupCode",
"PriceType", "EffectiveDate")
);


TIA

Eddie Sizemore






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.