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.
| Author |
Topic |
|
cjsmile999
Starting Member
5 Posts |
Posted - 2011-09-03 : 20:53:52
|
Hello Everyone, Yes I'm a complete noob at this, don't laugh :)! Still trying to learn this stuff. I have two strings in my DB one String Date (yyyy-mm-dd) and one String Time (hh:mm:ss). I want to combine the two into one datetime field, and to be honest I'm not sure where to begin. This is the error I'm receiving: "Msg 4104, Level 16, State 1, Line 2The multi-part identifier "trips.cxldate" could not be bound.Msg 4104, Level 16, State 1, Line 5The multi-part identifier "trips.cxltime" could not be bound." And this is what I have so far:declare @sdate as varchar(10)set @sdate = sl.sldatedeclare @stime as varchar(8)set @stime = sl.sltimeselect @sdate + ' ' + @stime from SL--Convert(dateadd(... Thank you for you're help!!! |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
cjsmile999
Starting Member
5 Posts |
Posted - 2011-09-03 : 23:15:23
|
| No really that all I have so far...I know it's pathetic! When I check it, it doesn't find any errors but when I execute it that's the error that it shows. I'm not sure if it makes a difference, but I'm using SQL 2005. I'm going to start with the example you provide and let you know how I come out. Thanks for your help. |
 |
|
|
cjsmile999
Starting Member
5 Posts |
Posted - 2011-09-03 : 23:43:52
|
| OK, I took your example, but it doesn't return any results. It says it completed successfully, but it doesn't return anything.declare @v1 datetimeselect @v1 = sldate + ' ' + sltimefrom SLwhere cost > 0Also, I noticed you have the @declare set to datetime. Does that mean when the strings are combined it's automatically converted to a datetime or do I still have to convert it?Thank you |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-04 : 00:04:06
|
is your attempt to store the values inside a variable or to show it? if its former, you might need a table variable if your query returns multiple date values and your variable can hold only one.it should be something likedeclare @datetable table(sdate datetime)insert @datetableselect sldate + ' ' + sltime from SL if its latter you just need only thisselect sldate + ' ' + sltime from SL ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2011-09-04 : 00:15:22
|
quote: Originally posted by cjsmile999 OK, I took your example, but it doesn't return any results. It says it completed successfully, but it doesn't return anything.declare @v1 datetimeselect @v1 = sldate + ' ' + sltimefrom SLwhere cost > 0Also, I noticed you have the @declare set to datetime. Does that mean when the strings are combined it's automatically converted to a datetime or do I still have to convert it?Thank you
I put it into a variable so you won't see a result set returned. I used a variable as that seemed to be what you wanted from your first post. If you don't care about reusing this anywhere, do it like visakh's example.Regarding the conversion, yes for that concatenation it'll implicitly convert it as that format is supported by datetime. You can check out the CONVERT function in BOL for more details.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
|
|
|
|
|