米琪卡哇伊
我一直对大多数程序员在数据访问层中混合UI逻辑的倾向感到失望:SELECT FirstName + ' ' + LastName as "Full Name", case UserRole when 2 then "Admin" when 1 then "Moderator" else "User" end as "User's Role", case SignedIn when 0 then "Logged in" else "Logged out" end as "User signed in?", Convert(varchar(100), LastSignOn, 101) as "Last Sign On", DateDiff('d', LastSignOn, getDate()) as "Days since last sign on", AddrLine1 + ' ' + AddrLine2 + ' ' + AddrLine3 + ' ' + City + ', ' + State + ' ' + Zip as "Address", 'XXX-XX-' + Substring( Convert(varchar(9), SSN), 6, 4) as "Social Security #"FROM Users通常,程序员这样做是因为他们打算将他们的数据集直接绑定到网格,并且它只是方便SQL Server格式服务器端而不是客户端上的格式。如上所示的查询非常脆弱,因为它们将数据层紧密耦合到UI层。最重要的是,这种编程风格彻底防止了存储过程的重用。