語法 A:
With TempBlock as (
Select *,
ROW_NUMBER() OVER(PARTITION BY B.Block_Id ORDER BY B.End_Date, B.Id) AS rk
from BlockData B Where IsDelete = 'N' and End_Date >= getDate())
Select * from TempBlock Where rk = 1
語法 B:
Select * from (
Select *,
ROW_NUMBER() OVER(PARTITION BY B.Block_Id ORDER BY B.End_Date, B.Id) AS rk
from BlockData B Where IsDelete = 'N' and End_Date >= getDate()) TempBlock
Where rk = 1
<Extension()>
Function SQLStr(ByVal Original As String) As String
Return Original.Replace("'", "''")
End Function
<Extension()>
Function SQLTrim(ByVal Original As String) As String
Return Original.Trim.Replace("'", "''")
End Function
End Module
C#
//Extension methods must be defined in a static class
public static class StringExtension
{
/// <summary>
/// 把 ' 取代成 ''
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string sqlStr(this string value)
{
return value.Replace("'", "''");
}