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 |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-12-09 : 06:49:09
|
Martyn writes "This is probably really stupid ;) But I'm a novice at SQL Server and am attempting to have a numbervar translated to a specific date. I know how the peform the translation manually, although am experiencing an issue with writing the specific SQL for this.An example of this is that the numbervar of 131401232. The method of tranlsating this to a specific date below and I have provided the relevant example for this below.What is the best method to write this specific SQL as I am experiencing a large difficulty with this at the moment.Many ThanksMartyn Jonesmartyn.jones@attentiv.comNumberVar Yyyy;NumberVar Mm;NumberVar Dd;Yyyy := Truncate ({CALL_HDW.CALLDAT_HDW} / 65536);Mm := Truncate (({CALL_HDW.CALLDAT_HDW}-(Yyyy * 65536)) / 256);Dd := {CALL_HDW.CALLDAT_HDW} - (Yyyy * 65536) - (Mm * 256);Date (Yyyy, Mm, Dd)YYYY = 2005Month = JuneDay = 16" |
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2005-12-09 : 07:05:39
|
DECLARE @dtInt INTDECLARE @Year INTDECLARE @Month INTDECLARE @Day INTSELECT @dtInt = CAST('131401232' AS INT)SELECT @Year = @dtInt / 65536, @Month = (@dtInt - (@dtInt / 65536) * 65536) / 256, @Day = (@dtInt - ((@dtInt / 65536) * 65536)) - (((@dtInt - (@dtInt / 65536) * 65536) / 256) * 256)SELECT @Year YYYY, @Month MM, @Day DD Duane. |
|
|
|
|
|