 |
|
VB.Net ขอถามเกี่ยวกับ Concat วัน-เดือน-ปี เวลา ใน sql sever 2005 หน่อยครับ |
|
 |
|
|
 |
 |
|
ขอถามเกี่ยวกับ Concat หน่อยครับ
ฐานข้อมูล

คือ ผมใช้ Data base sql sever 2005 ผมจะ concat ให้อยู่ใน คอมลัมน์เดียวกัน ในรูปแบบ แบบล่าง
2012-01-17 07:08:59
ผมจะเขียนคำสั่งยังไง
ตอนนี้ผมลองเขียนเอารูปแบบ วันที่ก่อน ผิดตรงไหนเหรอครับ
Code (VB.NET)
sql = ("SELECT concat(substring(C_Date,1,2),'-',substring(C_Date,3,2),'-',substring(C_Date,5,2)) As testcol FROM tenter")
command = New SqlCommand(sql, connection)
adapter = New SqlDataAdapter(command)
dataSt = New DataSet()
adapter.Fill(dataSt, sql)
มันเกิด Error บรรทัด
adapter.Fill(dataSt, sql)
Tag : .NET, Ms SQL Server 2005, Win (Windows App), VS 2005 (.NET 2.x)
|
ประวัติการแก้ไข 2012-01-17 16:33:50 2012-01-17 16:35:24 2012-01-17 16:36:20 2012-01-17 17:02:13 2012-01-17 17:03:05 2012-01-17 17:08:02 2012-01-18 09:10:14
|
 |
 |
 |
 |
Date :
2012-01-17 16:32:59 |
By :
SeedNew |
View :
1451 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Quote:SELECT concat(substring(C_Date,1,2),'-',substring(C_Date,3,2),'-',substring(C_Date,5,2)) As testcol FROM tenter
Query นี้รันผ่านหรือเปล่าครับ
|
 |
 |
 |
 |
Date :
2012-01-17 17:59:29 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ พี่ Mr.Win
ฟังก์ที่พี่ให้มาผมลองแล้วใช้ไม่ได้ครับ
งั้นผมขอแชร์ต่อแล้วกันนะครับ
ฟังก์ที่ใช้ได้
{fn CONCAT(string_exp1,string_exp2)}
Code ที่ผมเขียน
SELECT {FN concat(substring(C_Date,1,4),'-')}+{FN concat(substring(C_Date,3,2),'-')}+{FN concat(substring(C_Date,5,2),' ')}+{FN concat(substring(C_Time,1,2),':')}+{FN concat(substring(C_Time,3,2),':')}+{FN concat(substring(C_Time,5,2),'')} FROM tenter
ผลการรัน

|
 |
 |
 |
 |
Date :
2012-01-18 09:28:59 |
By :
SeedNew |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Good Jobs ! 
|
 |
 |
 |
 |
Date :
2012-01-18 09:55:36 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|