| Author |
Topic |
|
ra_pa_ta
Starting Member
13 Posts |
Posted - 2011-09-23 : 12:21:26
|
| The table I need to update has a primary key on two columns codeid and priceid the codeid 22 will have a new price id and I have to update the table .how do I do it this is what I have so farUpdate A Set A.Codeid = T.tintFeatureCode,A.PriceID = T.PriceID,A.strFlag = T.strFlag,A.LastUpdate = T.LastUpdateFrom dbo.tblrefFeaturePrice As A Inner Join dbo.Sourcefile As T On T.Codeid = A.Codeid Where A.LastUpdate < T.LastUpdate |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-23 : 12:29:00
|
| if the table has primary key on two columns codeid and priceid and you've new record coming up for codeid 22 with new priceid then it should be an insert not an update as its a new unique combination.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
paultech
Yak Posting Veteran
79 Posts |
Posted - 2011-09-27 : 10:07:27
|
| I couldn't understand the relation between the code you post and what you want , but my suggestion to you , instead of updateing the record . you can delete it and insert a new one again with the new values of the primary key , because the PK here is not autoincreament |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2011-09-27 : 12:45:53
|
| "you can delete it and insert a new one again with the new values of the primary key"If that's what the O/P wants to do then an UPDATE will be better. |
 |
|
|
jassi.singh
Posting Yak Master
122 Posts |
Posted - 2011-09-27 : 13:51:26
|
| Hi,Update query shoud work and update the priceid. you should use codeid and old priceid in where clause and set priceid with new priceid and please first check whether combination of codeid and new priceid does not exist in the table.Please mark answer as accepted if it helped you.Thanks,Jassi Singh |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-27 : 23:05:27
|
quote: Originally posted by jassi.singh Hi,Update query shoud work and update the priceid. you should use codeid and old priceid in where clause and set priceid with new priceid and please first check whether combination of codeid and new priceid does not exist in the table.Please mark answer as accepted if it helped you.Thanks,Jassi Singh
no way to do it here other than manually quoting replying and telling that this is fine or something------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
vmvadivel
Yak Posting Veteran
69 Posts |
Posted - 2011-09-27 : 23:07:52
|
| >>no way to do it here other than manually quoting replying and telling that this is fine or somethingThanks for that clarification. I was searching for the option all through the site for past few mins :)Best RegardsVadivelhttp://vadivel.blogspot.com |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-27 : 23:09:28
|
quote: Originally posted by vmvadivel >>no way to do it here other than manually quoting replying and telling that this is fine or somethingThanks for that clarification. I was searching for the option all through the site for past few mins :)Best RegardsVadivelhttp://vadivel.blogspot.com
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|