ลบ กพ 2010 ทั้งหมด
DELETE FROM [TABLE_NAME]
WHERE (YEAR(ORDERDATE)=2010) AND (MONTH(ORDERDATE)=2)
ลบ ตามตัวแปรแบบ parameter
DELETE FROM [TABLE_NAME]
WHERE (YEAR(ORDERDATE)=YEAR(@REQUIRE_DELETE_DATE)) AND (MONTH(ORDERDATE)=(MONTH(@REQUIRE_DELETE_DATE))
หรือ
dim myDate as DateTime = วันที่ที่ต้องการ
dim myCommand as StringBuilder = New StringBuilder()
myCommand.AppendLine(" DELETE FROM [TABLE_NAME] ")
myCommand.AppendLine(" WHERE (YEAR(ORDERDATE)=" + myDate.Year.ToString() + ") ")
myCommand.AppendLine(" AND (MONTH(ORDERDATE)=" + myDate.Month.ToString() +")" )
ตามที่คุณ bureEye บอก ส้มโอใช้อย่างนี้ค่ะ
Dim myDate As DateTime = Now()
sqldel = "delete from test2 where stockcode in (select stockcode from test1 WHERE (YEAR(etawhh)=" + Now().Year.ToString() + ") AND (MONTH(etawhh)=" + Now().Month.ToString() + "))"
cmd = New SqlCommand(sqldel, MConn)
MConn.Open()
cmd.ExecuteNonQuery()
MConn.Close()