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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 convert from datetime to bigint

Author  Topic 

wawansur
Starting Member

44 Posts

Posted - 2009-09-07 : 04:00:54
Could we convert data type from datetime to integer or bigint?

I'm nothing just gonna being

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-07 : 04:01:34
how do you want to convert ? example ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-09-07 : 04:02:43
or maybe

select convert(int, convert(varchar(10), getdate(), 112))

?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

wawansur
Starting Member

44 Posts

Posted - 2009-09-07 : 04:33:39
I have data like this.

FPostID
1900-01-01 00:12:30.913
1900-01-01 00:12:30.950
1900-01-01 00:12:30.967
1900-01-01 00:12:31.000
1900-01-01 00:12:31.103
1900-01-01 00:12:30.533
1900-01-01 00:12:30.497
1900-01-01 00:12:31.157
1900-01-01 00:12:31.173
1900-01-01 00:12:31.297
1900-01-01 00:12:31.313


i want to convert this data into int or bigint, so i could sort it

I'm nothing just gonna being
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-07 : 04:40:36
order by convert(int,replace(replace(replace(replace(FPostID,'-',''),' ',''),':',''),'.',''))


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-07 : 04:49:44
quote:
Originally posted by wawansur

I have data like this.

FPostID
1900-01-01 00:12:30.913
1900-01-01 00:12:30.950
1900-01-01 00:12:30.967
1900-01-01 00:12:31.000
1900-01-01 00:12:31.103
1900-01-01 00:12:30.533
1900-01-01 00:12:30.497
1900-01-01 00:12:31.157
1900-01-01 00:12:31.173
1900-01-01 00:12:31.297
1900-01-01 00:12:31.313


i want to convert this data into int or bigint, so i could sort it

I'm nothing just gonna being


Why dont you sort as datetime?

Madhivanan

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

wawansur
Starting Member

44 Posts

Posted - 2009-09-07 : 04:52:10
select*from StckKlr
order by convert(int,replace(replace(replace(replace(FPostID,'-',''),' ',''),':',''),'.',''))


I Have this error messages


Server: Msg 245, Level 16, State 1, Line 1
Syntax error converting the varchar value 'Jan119001212AM' to a column of data type int.

I'm nothing just gonna being
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-07 : 04:57:59
order by convert(datetime,FPostID)

(Thx for that madhi, I was blind )


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

wawansur
Starting Member

44 Posts

Posted - 2009-09-07 : 05:02:01
quote:
Originally posted by webfred

order by convert(datetime,FPostID)

(Thx for that madhi, I was blind )


No, you're never too old to Yak'n'Roll if you're too young to die.




Its works

Thx

I'm nothing just gonna being
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-07 : 05:05:08
quote:
Originally posted by webfred

order by convert(datetime,FPostID)

(Thx for that madhi, I was blind )


No, you're never too old to Yak'n'Roll if you're too young to die.


No problem

Madhivanan

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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-07 : 05:06:56
quote:
Originally posted by wawansur

quote:
Originally posted by webfred

order by convert(datetime,FPostID)

(Thx for that madhi, I was blind )


No, you're never too old to Yak'n'Roll if you're too young to die.




Its works

Thx

I'm nothing just gonna being


If FPostID is of datetime data, you dont need any convertion
Simply use

order by FPostID

Madhivanan

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

- Advertisement -