Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Need assistance in writing a script that will update a field by concatenating 3 columns while also specifying the date format in the new fieldHere is what I want to create new Field of(adm,Disch,LastName)Sample of current data and FormatAdmission dateJan 15 2013 12:00AMDischarge DateJan 20 2013 12:00AMLast NameSmithWhat current “New Field” looks like.Jan 15 2013 12:00AM Jan 20 2013 12:00AMSmithWhat New Field” needs to look like.11520131202013Smith
tkizer
Almighty SQL Goddess
38200 Posts
Posted - 2014-05-19 : 15:39:03
You should not be creating a new column like this. If you need this for application purposes, then return the 3 columns separately and then do the concatenation in your application. If you do decide to create this column, you should do this as a computed column.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/
MuralikrishnaVeera
Posting Yak Master
129 Posts
Posted - 2014-05-20 : 08:12:06
May be this...
DECLARE @Admission_date DATETIME='Jan 15 2013 12:00AM' ,@Discharge_Date DATETIME='Jan 20 2013 12:00AM' ,@Last_Name VARCHAR(1024)='Smith'SELECT REPLACE(CONVERT(VARCHAR,CAST(@Admission_date AS DATETIME),110),'-','')+REPLACE(CONVERT(VARCHAR,CAST(@Discharge_Date AS DATETIME),110),'-','')+@Last_Name
---------------Murali KrishnaYou live only once ..If you do it right once is enough.......