Morning All,This is driving me up the wall! I've used some info on here to generate random dates within a given range and also random times - independently they work fine, but I can't seem to join them into a single field of datetime. I'm not sure why. The following snippet works fine as two independent fields:[code="sql"]select CAST(CAST(ABS(CHECKSUM(NEWID()))%(780)+(33968) AS DATETIME) as DATE) as theDate, CAST(CAST(DATEADD(milliSECOND,ABS(CHECKSUM(NEWID()))%86400000 ,'00:00') AS TIME) as varchar(50)) as theTime[/code]But when I try to make it a single datetime field: [code="sql"]select CAST(cast(cast(CAST(ABS(CHECKSUM(NEWID()))%(780)+(33968) AS DATETIME) as date) as varchar(50)) + ' ' + cast(CAST(CAST(DATEADD(milliSECOND,ABS(CHECKSUM(NEWID()))%86400000 ,'00:00') AS TIME) as varchar(50)) as varchar(50)) as datetime) [/code]Which returns with: Conversion failed when converting date and/or time from character string.So what I am really looking for is a way to join those two values into a single datetime field... Or failing that that how to generate random dates within a range including random times... As always, your thoughts and help are appreciatedCheersAlex
↧