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
 Inserting a date field within a string statement?

Author  Topic 

Maverick_
Posting Yak Master

107 Posts

Posted - 2011-01-07 : 05:34:49
Hi all and happy new year!

I am trying to insert a date field (log_effective_date) from a table into a string but I am not sure how to or how to get it working.

Here is how it looks so far, I am trying to put it in the highlighted part of the code:

UPDATE
engineer.jsl
SET
log_effective_date =
(SELECT
temp.new_date_time
FROM
sbs.temp_jsl_data temp
WHERE
temp.change_type = 'overwrite' AND
temp.job_no = engineer.jsl.job_no AND
temp.jln = engineer.jsl.jln),
log_notes = 'Original Effective date was: ' || log_effective_date
WHERE
EXISTS
(SELECT
1
FROM
sbs.temp_jsl_data temp
WHERE
temp.change_type = 'overwrite' AND
temp.job_no = engineer.jsl.job_no AND
temp.jln = engineer.jsl.jln);

Anyone have any suggestions?

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-01-07 : 07:07:34
are you getting any error while executing this query? Also, if possible please provide us the tables structure and the details of the requirements through an example!!

By the way if you just want to know how to convert a date into string format then use following syntax over date Column/field

Convert(Varchar(15),DateColumn,101|102|...|112)

The third parameter could be any starting from 101 till 112 and convert will change the datatype of the unit to Varchar.


Cheers!
MIK
Go to Top of Page

Maverick_
Posting Yak Master

107 Posts

Posted - 2011-01-07 : 12:07:50
Hi MIK

I ended up working out (eventually): log_text = 'Date was: ' || to_char(log_effective_date, 'dd/mm/yyyy hh24:mi:ss')

Thanks though!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-08 : 01:09:46
I dont think this is MS SQL Server. || is not concatenation operator in sql server nor do we have to_Char(). It would be better if you can post it in relevant forums in future for getting quick solutions. This is MS SQL Server forum

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-01-12 : 03:11:03
Yes. The code he posted is for ORACLE.

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -