使用case语句在select语句中显示某些列

时间:2015-09-22 11:07:30

标签: sql sql-server if-statement case

有没有办法使用CASE语句在select语句中显示某些列?

目前我正在使用以下SQL来执行此操作

BEGIN
IF( @ISUSERROLE = 1)
     SELECT 
    t       PONumber                      = [RAH_PONumber]
           ,RAType                       = rt.[RAT_Type]
           ,ChargeableAmount             = [RAH_ChargeableAmount]
     FROM [T_RA_Header] rh
     INNER JOIN dbo.T_RA_Type rt ON rt.RAT_ID = rh.[RAH_RAT_ID]
     INNER JOIN dbo.T_RA_Status rs ON rs.RAS_ID = rh.[RAH_RAS_ID]
     WHERE
          rh.RAH_RAI_ID = @RAI_ID

    ELSE IF (@ISUSERROLE = 2)
          SELECT   
           PONumber                     = [RAH_PONumber]
          ,RANumber                     = [RAH_RANumber]
          ,RAType                       = rt.[RAT_Type]
          ,RAStatus                     = rs.RAS_Status
          ,RAUploadedBy                 = [RAH_UploadedByUserName]
          ,UploadedOn                   = [RAH_UploadedOn]
          ,ChargeableAmount             = [RAH_ChargeableAmount]

     FROM [T_RA_Header] rh
     INNER JOIN dbo.T_RA_Type rt
          ON rt.RAT_ID = rh.[RAH_RAT_ID]
     INNER JOIN dbo.T_RA_Status rs
          ON rs.RAS_ID = rh.[RAH_RAS_ID]
     WHERE
          rh.RAH_RAI_ID = @RAI_ID
END

从这可以使用CASE语句?或者是我唯一的方式

1 个答案:

答案 0 :(得分:0)

case

if (Meteor.isServer) {
  Meteor.methods({
    foo: function (data) {
      try {
        var result= HTTP.post("example.com", {
          data: data
        });
        return result;
      }
      catch (error) {
        // todo: check if the error is 400
        console.log("abc");
        return 0;
      }
    }
  });
}