dynamic query creation

  • when trying to ececute teh querty iam getting folloing messgae...please correct me where iam going wrong..

    use tst

    DECLARE @document varchar(64)

    SELECT @document = 'Reflectors are vital safety ''"'' components of your bicycle.'

    DECLARE @sSql varchar(64)

    SET @sSql= 'SELECT';

    set @sSql = @sSql + ' CASE WHEN CHARINDEX(''"'', @document) > 0 THEN ''0.0'' ELSE @document END';

    EXEC @sSQL

    error details ...

    Msg 203, Level 16, State 2, Line 9

    The name 'SELECT CASE WHEN CHARINDEX('"', @document) > 0 THEN '0.0' ELSE' is not a valid identifier.

  • EXEC (@sSQL)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply