locked
Sql Query Problem RRS feed

  • Question

  • User54259136 posted

    Hi,

    Declare

    @msg nvarchar(2000

    )

    set

    @msg =

    'Select distinct(Name)from tblWsp inner join tblWspAccessCtrl

    on tblWsp.WspId=tblWspAccessCtrl.WspId inner join tblUserGroupMship on tblUserGroupMship.UserGroupId=tblWspAccessCtrl.UserGroupId

    inner join tblUser on tblUser.UserId=tblUserGroupMship.UserId where 1=1 '

    set

    @msg =@msg + 'and ' +

    'tblUser.UserId=1'

    Begin tran

    try

    excute @msg


     

    catch

    {}

    set @msg =@msg + 'and (SYSDATETIME() between tbluser.EffectiveFrom and tblUser.EffectiveTo)

    and (SYSDATETIME() between tblUserGroupMship.EffectiveFrom and tblUserGroupMship.EffectiveTo)

    and (SYSDATETIME() between tblWsp.EffectiveFrom and tblwsp.EffectiveTo) and (SYSDATETIME() between tblWspAccessCtrl.EffectiveFrom and tblWspAccessCtrl.EffectiveTo)'

    try

    { excute @msg}

    catch

    {}

     

    This is not  running. My problem is that if user Condition false than it show message.

    excute @msg  is also not work.

    pls identify my problem

     

     

     

     

    Wednesday, October 5, 2011 6:31 AM

Answers

  • User-126497635 posted

    executesql @msg

    Also take VARCHAR(MAX) instead of VARCHAR(2000)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 5, 2011 6:57 AM