2016年10月3日 星期一

[研究] SQL 語法 & (位元and) 邏輯運算符號在 .aspx 和 .aspx.cs 中的差異

[研究] SQL 語法 & (位元and) 邏輯運算符號在 .aspx 和 .aspx.cs 中的差異

2016-10-03

在.aspx 中

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:pmsConnectionString %>" SelectCommand="
SELECT
A.Id,
A.OID,

A.A00 | case when B.A00 is null then 0 else null end A00,
--A.A01 | case when B.A01 is null then 0 else null end A01,
(A.A10 | case when B.A10 is null then 0 else null end &amp;
A.A11 | case when B.A11 is null then 0 else null end )A1,
A.A20 | case when B.A20 is null then 0 else null end A20,
A.A30 | case when B.A30 is null then 0 else null end A30,
A.A40 | case when B.A40 is null then 0 else null end A40,
A.A50 | case when B.A50 is null then 0 else null end A50,
A.A60 | case when B.A60 is null then 0 else null end A60,
(A.A70 | case when B.A70 is null then 0 else null end &amp;
A.A71 | case when B.A71 is null then 0 else null end) A71,
A.A72 | case when B.A72 is null then 0 else null end A72,
A.A80 | case when B.A80 is null then 0 else null end A80,
(A.A90 | case when B.A90 is null then 0 else null end &amp;
A.A91 | case when B.A91 is null then 0 else null end)
from TableA   A, TableB    B
"></asp:SqlDataSource>


在.aspx.cs 中要改寫成

SqlDataSource1.SelectCommand = @"
SELECT
A.Id,
A.OID,

A.A00 | case when B.A00 is null then 0 else null end A00,
--A.A01 | case when B.A01 is null then 0 else null end A01,
(A.A10 | case when B.A10 is null then 0 else null end &
A.A11 | case when B.A11 is null then 0 else null end )A1,
A.A20 | case when B.A20 is null then 0 else null end A20,
A.A30 | case when B.A30 is null then 0 else null end A30,
A.A40 | case when B.A40 is null then 0 else null end A40,
A.A50 | case when B.A50 is null then 0 else null end A50,
A.A60 | case when B.A60 is null then 0 else null end A60,
(A.A70 | case when B.A70 is null then 0 else null end &
A.A71 | case when B.A71 is null then 0 else null end) A71,
A.A72 | case when B.A72 is null then 0 else null end A72,
A.A80 | case when B.A80 is null then 0 else null end A80,
(A.A90 | case when B.A90 is null then 0 else null end &
A.A91 | case when B.A91 is null then 0 else null end)
from TableA   A, TableB    B
";

(完)

沒有留言:

張貼留言