I have a table called PriceName having schema
CREATE TABLE PriceName (PriceNameID INT IDENTITY(1,1), Price
DECIMAL(9,2), PriceName VARCHAR(100))
In this table the data is populated in the Price field. Now i want to
update this table to update the PriceName column, that shows the range
in which that price lies.
Ex is shown below
PriceNameID Price PriceName
1 200 0-200
2 300 200-300
3 350 300-350
.....
....
99 1500 1400-1500
100 NULL 1500 & Above
Can someone suggest me the update query for this '
RegardsUPDATE PriceName p1
SET PriceName = ISNULL(CONVERT(VARCHAR(9), (SELECT MAX(p2.Price) FROM
PriceName p2 WHERE p2.Price < p1.Price)), '0') +
ISNULL(' - ' + CONVERT(VARCHAR(9), Price), ' & Above')
Jacco Schalkwijk
SQL Server MVP
"Prashant Thakwani" <thakwani@.rediffmail.com> wrote in message
news:bf0d42bf.0403120517.3815a063@.posting.google.com...
> I have a table called PriceName having schema
>
> CREATE TABLE PriceName (PriceNameID INT IDENTITY(1,1), Price
> DECIMAL(9,2), PriceName VARCHAR(100))
>
> In this table the data is populated in the Price field. Now i want to
> update this table to update the PriceName column, that shows the range
> in which that price lies.
> Ex is shown below
> PriceNameID Price PriceName
> 1 200 0-200
> 2 300 200-300
> 3 350 300-350
> .....
> ....
> 99 1500 1400-1500
> 100 NULL 1500 & Above
>
>
> Can someone suggest me the update query for this '
>
> Regards|||Have u run that script '
I am getting the following error
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'p1'.
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near ')'.
Pls take care of this
Regards
*** Sent via Developersdex http://www.examnotes.net ***
Don't just participate in USENET...get rewarded for it!|||UPDATE PriceName
SET PriceName = ISNULL(CONVERT(VARCHAR(9), (SELECT MAX(p2.Price) FROM
PriceName p2 WHERE (p2.Price < PriceName.Price) OR PriceName.Price IS
NULL)), '0') +
ISNULL(' - ' + CONVERT(VARCHAR(9), Price), ' & Above')
Jacco Schalkwijk
SQL Server MVP
"Prashant Thakwani" <thakwani@.rediffmail.com> wrote in message
news:OJxZIkDCEHA.624@.TK2MSFTNGP10.phx.gbl...
> Have u run that script '
> I am getting the following error
> Server: Msg 170, Level 15, State 1, Line 1
> Line 1: Incorrect syntax near 'p1'.
> Server: Msg 170, Level 15, State 1, Line 3
> Line 3: Incorrect syntax near ')'.
>
> Pls take care of this
> Regards
>
> *** Sent via Developersdex http://www.examnotes.net ***
> Don't just participate in USENET...get rewarded for it!
Monday, March 26, 2012
Query problem
Labels:
database,
identity,
int,
microsoft,
mysql,
oracle,
pricedecimal,
pricename,
pricenameid,
query,
schemacreate,
server,
sql,
table,
varchar
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment