由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - 一个关于T-SQL的问题
相关主题
转换成时间的格式 MS SQLT-SQL 问题
SQL Server - convert datetime to a string YY-MM-DD HHsql请教
convert datetime to ''random error for CAST( MONEY AS VARCHAR)
SQL find distinct values in large tableSQL问题请教: add one more column
date format转换问题请教SQL combine two columns from two different tables no shared (转载)
Oracle Group and Index question请教一下高手,包子答谢!
再请教大牛一个问题How to convert this datetime in SQL Server?
有大侠知道怎么format下面这个query的时间么誰來幫我開來開悄? Interesting SQL query
相关话题的讨论汇总
话题: convert话题: monthid话题: datetime话题: 15话题: sql
进入Database版参与讨论
1 (共1页)
B****a
发帖数: 154
1
Need to convert a varchar column to datetime format.
The column is like:
monthid
200811
200711
200610
200510
I need them to be like
2008/11/15
2007/11/15
2006/10/15
2005/10/15
i.e., convert it to the 15th date of the month...how can I do this in T-SQL?
thanks a lot!!!
j*****n
发帖数: 1781
2
SELECT convert(datetime, monthid + '15')
FROM table
B****a
发帖数: 154
3
this doesnot work...
e.g., it returns 2449-07-26 for 200710

【在 j*****n 的大作中提到】
: SELECT convert(datetime, monthid + '15')
: FROM table

j*****n
发帖数: 1781
4
en, then try this:
SELECT convert(datetime, convert(int, monthid + '15'))
FROM table

【在 B****a 的大作中提到】
: this doesnot work...
: e.g., it returns 2449-07-26 for 200710

B****a
发帖数: 154
5
thanks for your reply...but it is still the same...

【在 j*****n 的大作中提到】
: en, then try this:
: SELECT convert(datetime, convert(int, monthid + '15'))
: FROM table

j*****n
发帖数: 1781
6
shot, then go this way...
SELECT convert(datetime, left(monthid,4) + '/' + right(monthid,2) + '/15')
FROM table
B****a
发帖数: 154
7
OMG, it works this time!! :)
thanks a lot for your time and patience! Thanks!!!!

【在 j*****n 的大作中提到】
: shot, then go this way...
: SELECT convert(datetime, left(monthid,4) + '/' + right(monthid,2) + '/15')
: FROM table

n********6
发帖数: 1511
8
substring()
updates: Use convert.
Sorry. Should use convert (to datetime format). Jackrun is right. Substring
will return varchar type.

【在 B****a 的大作中提到】
: Need to convert a varchar column to datetime format.
: The column is like:
: monthid
: 200811
: 200711
: 200610
: 200510
: I need them to be like
: 2008/11/15
: 2007/11/15

1 (共1页)
进入Database版参与讨论
相关主题
誰來幫我開來開悄? Interesting SQL querydate format转换问题请教
请教2个sql query 问题Oracle Group and Index question
请问sql server里面怎么输出变量到文本文件?再请教大牛一个问题
求助:如何ColumName 作为变量放入query有大侠知道怎么format下面这个query的时间么
转换成时间的格式 MS SQLT-SQL 问题
SQL Server - convert datetime to a string YY-MM-DD HHsql请教
convert datetime to ''random error for CAST( MONEY AS VARCHAR)
SQL find distinct values in large tableSQL问题请教: add one more column
相关话题的讨论汇总
话题: convert话题: monthid话题: datetime话题: 15话题: sql