April 18, 2006 at 11:26 am
I have a temp table that I need to update. Can you please tell me if my syntax is correct in the following?? I am getting an error at the keyword 'if' and at the '='. (obviously, something is wrong, but I am not sure how to fix it!)
Thank you!!!!!
update
t
if UserWeightUnit is null
set UserWeightUnit = 'kg', UserWeightFactor = 1
if UserHeightUnit is null
set UserHeightUnit = 'cm', UserHeightFactor = 1
from
@tmp t
April 18, 2006 at 11:54 am
I'm sure there is a better way, but you could do it like this...
UPDATE t
set UserWeightUnit = 'kg', UserWeightFactor = 1
FROM @tmp t
WHERE UserWeightUnit is null
UPDATE t
set UserHeightUnit = 'cm', UserHeightFactor = 1
FROM @tmp t
WHERE UserHeightUnit is null
If it needs to happen all at once it could be wrapped in a transaction...
April 18, 2006 at 12:00 pm
April 18, 2006 at 12:05 pm
April 18, 2006 at 12:07 pm
April 18, 2006 at 12:09 pm
April 18, 2006 at 12:17 pm
April 18, 2006 at 12:31 pm
I'm not really sure what you're trying to do with this one... Are you trying to Set UserWeightFactor = UnitConversion.Factor WHERE ...?
If so why not something like this... (Btw check this for syntax errors, I'd need more of the table definitions and such to test this.)
UPDATE t
SET t.userweightfact = uc.Factor
FROM @tmp t LEFT JOIN UnitConversion uc ON uc.ToUnit = t.UserWeightUnit
AND uc.FromUnit = 'kg'
WHERE UserWeightUnit <> 'cm'
April 18, 2006 at 12:46 pm
April 18, 2006 at 1:01 pm
Check out this thread also on Colation issues...
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=9&messageid=252711
heres another one...
http://www.experts-exchange.com/Databases/Q_21048175.html
hope these help.
-Luke.
April 18, 2006 at 1:23 pm
April 18, 2006 at 2:40 pm
ok, I am a bit stumped. True, the collation of the columns in UnitConversion are swedish, but in my tmp table, there is no collation...so why a conflict?? Can I set a tmp table up with collation? The variables and the columns are set up as the same data type as the UC table. Any thoughts????
April 18, 2006 at 3:36 pm
ok, in case anyone is reading this, I was able to get around the error by putting a collation clause after my column in the following manner:
update
t
set t.UserHeightFactor = uc.Factor
from
@tmp t
left join Medicompass31.dbo.UnitConversion uc
on uc.ToUnit = t.UserHeightUnit COLLATE SQL_SwedishStd_Pref_CP1_CI_AS
and uc.FromUnit = 'cm'
this fixed the issue. Thanks again to Luke, you were a great help to me today!!!!
April 19, 2006 at 5:59 am
Viewing 14 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply