Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Syntax

Author  Topic 

JVisconti
Starting Member

47 Posts

Posted - 2009-09-22 : 08:13:53
In a query I have running, I created a new column through the query and I now want, when the query runs, to take the values in one column and subtract it from another column and put the new data in the new column I created. So far the only syntax I have come up with is:

RESPONSETIME = OPENDATETIME - UPDATEDATE,


I am a C# programmer, so the SQL part is still giving me trouble.

Thanks

vedjha
Posting Yak Master

228 Posts

Posted - 2009-09-22 : 08:22:27
update table set column1=column2-column3 where condition

Ved Prakash Jha
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2009-09-22 : 09:11:24
What are the data types from columns 1,2 and 3?

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

JVisconti
Starting Member

47 Posts

Posted - 2009-09-22 : 09:15:36
the data types are currently a DATEPART being converted to VARCHAR.
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-09-22 : 09:17:42
quote:
Originally posted by JVisconti

the data types are currently a DATEPART being converted to VARCHAR.



Convert to int and perform subtraction!

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2009-09-22 : 10:51:45
Well, given this formula (RESPONSETIME = OPENDATETIME - UPDATEDATE) for it to turn in to something sensible the data types for OPENDATETIME and UPDATEDATE needs to be datetime, and RESPONSETIME needs to be int. Then you can do this:

UPDATE mytable SET RESPONSETIME = DATEFIDD(ss, OPENDATETIME, UPDATEDATE) WHERE ...

- Lumbago
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-09-22 : 13:14:33
quote:
Originally posted by JVisconti

the data types are currently a DATEPART being converted to VARCHAR.

DATEPART? What are the actual data types and values you have for OPENDATETIME and UPDATEDATE? And what do you want as output to store in RESPONSETIME?
Go to Top of Page

JVisconti
Starting Member

47 Posts

Posted - 2009-09-22 : 15:48:22
The info that Lumbago put here should work the way I want it to. All I was looking to return was the amount of time between OPENDATETIME and UPDATEDATE and put it into RESPONSETIME.

Thanks!
Go to Top of Page
   

- Advertisement -