 |
|
[.NET]
ถามความหมายของคำสั่งนี้หน่อยคะ เป็นคำสั่ง sql ในการเลือกสุนัขที่ครบกำหนดที่จะต้องฉีดวัคซีนวันนี้คะ |
|
 |
|
|
 |
 |
|
เป็นคำสั่ง sql ในการเลือกสุนัขที่ครบกำหนดที่จะต้องฉีดวัคซีนวันนี้คะ
ตอนแรกใช้คำสั่งรูปแบบนี้คะ
Code (VB.NET)
1. select Dog_no,Dog_name,Dog_sex,Dog_color,Vacci_no,Vac_no,Vac_ID,Vac_Name
2. from Vaccination, Vaccination_detail, kennel_dog,Vaccine_Type
3. where Dog_No = Dog_ID and Vacci_ID = Vacci_No and Vac_no = Vac_ID
4. and next_date = getdate()
ไม่ขึ้นข้อมูลมาให้คะ ขึ้นให้แต่หัว attribute เลยลองหาข้อมูล ได้ตัวนี้มา
Code (VB.NET)
1. select Dog_no,Dog_name,Dog_sex,Dog_color,Vacci_no,Vac_no,Vac_ID,Vac_Name
2. from Vaccination, Vaccination_detail, kennel_dog,Vaccine_Type
3. where Dog_no = Dog_Id and Vacci_ID = Vacci_No and Vac_no = Vac_ID
4. and convert(datetime, floor(convert(float, next_date))) = convert(datetime, floor(convert(float, getdate())))
ใช้คำสั่งนี้รันออกมาถูกต้องคะ
เลยอยากราบว่า code บรรทัดนี้หมายความว่าไงคะ
Code (VB.NET)
1. convert(datetime, floor(convert(float, next_date))) = convert(datetime, floor(convert(float, getdate())))
ช่วยอธิบายให้หน่อยนะคะ
Tag : - - - -
|
|
 |
 |
 |
 |
Date :
2010-02-08 07:23:59 |
By :
numsom |
View :
1689 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
SELECT CEIL(10.19) AS ceil_value,
FLOOR(10.19) AS floor_value
ceil_value floor_value
11 10
ผมไม่ทราบว่า next_date คุณ datatype เป็นอะไรครับ ปกติแล้ว
next_date = getdate() compare กันได้เลย ถ้า next_date datatype เป็น datetime แต่ว่า getdate() จะได้ วัน เดือน ปี ชั่วโมง นาที วินาทีด้วย
ดังนั้น แสดงว่า...
next_date คุณเก็บแค่ วัน เดือน ปี พอมา compare กับ getdate() ที่เป็น วัน เดือน ปี ชั่วโมง นาที วินาที จึงไม่เท่ากัน
ตัวอย่าง
next_date getdate()
12.04.2553 00:00:00 ไม่เท่ากับ 12.04.2553 12:25:14
|
 |
 |
 |
 |
Date :
2010-02-08 08:09:10 |
By :
numenoy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
convert(float, next_date) แปลง data type เป็น float - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308
จะเห็นว่ามี ทศนิยมด้วย
ถ้า next_date เป็น datetime การแปลงแบบนี้เขาเรียกว่า timespan ต่างกันเป็น มิลิวินาที
floor(convert(float, next_date)) คือเอาค่าจำนวนเต็มน้อยที่สุดหรือเท่ากับ เช่น 12.3 จะเอาจำนวนเต็ม 12 เท่านั้น คือไม่เอา ชั่วโมง นาที วินาทีี นั่นเอง
convert(datetime, floor(convert(float, next_date))) convert เป็น datetime กลับมาอีกที จะได้ว่า เป็น วัน เดือน ปี เท่านั้น ไม่เอา ชั่วโมง นาที วินาที
เช่น 07-02-2553 00:00:00 คือ วันที่ 7 เดือน กุมภาพันธ์ 2553 เวลา เที่ยงคืนตรงแป๊ะ
|
 |
 |
 |
 |
Date :
2010-02-08 09:23:16 |
By :
numenoy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ numenoy มากๆเลยคะ
|
 |
 |
 |
 |
Date :
2010-02-08 10:06:16 |
By :
numsom |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีประโยชน์มาก ๆ เลยค่ะ ตอนนี้กวางมีปัญหาเรื่องวันที่อยู่ ขอบคุณมาก ๆ นะคะ คุณ numenoy และ มะส้มจ้า
|
 |
 |
 |
 |
Date :
2010-02-08 14:32:14 |
By :
Kwang196 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|