存储过程和asp.net可编程性;变量或SQL

时间:2015-08-04 15:38:22

标签: asp.net sql-server stored-procedures programmatically-created databound

尝试显示用户姓氏,名字---网站

我需要在Lastname之后插入一个逗号和空格到GridView。 我试图在SQL中添加CASE语句并且无法搞清楚。

也许我需要使用@parameter(标量变量?)来抽象 内存从CASE语句中读取;或者我的语法错了,我只是不这样做 理解。

SELECT 
    CASE
       WHEN IsNull(people_Table.firstName, '') = ''
         THEN CONCAT(people_Table.lastName, ', ', people_Table.firstName) 
         ELSE people_Table.lastName
    END as fullName, 
    people_Table.website
FROM 
    people_Table 
INNER JOIN 
    membership_Table on people_Table.ID = membership_Table.personID
WHERE 
    rectype = 'Master'
    AND membershipType = 'Business'
    AND expirationDate > GetDate()
ORDER BY 
    people_Table.lastName

获取SQL Server错误:

  

Msg 208,Level 16,State 1,Line 1
  无效的对象名称'people_Table'。

否则我想我应该在模板中使用asp databoundevent。

对性能和安全性有什么好处?

1 个答案:

答案 0 :(得分:1)

SELECT    ISNULL(people_Table.lastName + ', ', '') 
            + ISNULL(people_Table.firstName , '') as fullName
        , people_Table.website
FROM people_Table INNER JOIN membership_Table on people_Table.ID =
membership_Table.personID
WHERE rectype = 'Master'
AND membershipType = 'Business'
AND expirationDate > GetDate()
ORDER BY people_Table.lastName

或者

SELECT    COALESCE(people_Table.lastName + ', ', '') 
            + COALESCE(people_Table.firstName , '') as fullName
        , people_Table.website
FROM people_Table INNER JOIN membership_Table on people_Table.ID =
membership_Table.personID
WHERE rectype = 'Master'
AND membershipType = 'Business'
AND expirationDate > GetDate()
ORDER BY people_Table.lastName