Help

  • Hi All,

    I need help about the matter about my syntax .

    when I execute this,I take this error message :

    Server: Msg 207, Level 16, State 3, Line 1

    Invalid column name 'A'.

    I know the problem but I don't know how I can solve it. I have to put @ozelkategori in quotation marks.

    Please help me.

    Thanks all.

    Declare  @urunid int

    Declare  @fiyatgrup nvarchar(30)

    Declare  @ozelkategori nvarchar(30)

    Declare  @sql nvarchar(300)

    Declare @tirnak char

    set @urunid=123

    set @fiyatgrup='Fiyat2'

    set @ozelkategori='A'

    set @sql=' SELECT UrunID, FiyatKategorisi, AstSatFiyati, ASFBrm, '+@fiyatgrup+','+@fiyatgrup+'Brm'+

             ' FROM dbo.GenelSFiyatlari '+

      ' WHERE     UrunID =' +convert(nvarchar,@urunid)+' AND FiyatKategorisi='+@ozelkategori+''

     

    execute (@sql)

     

     

  • Hi,

    The bit at the end of the code should be

    AND FiyatKategorisi='''

    +@ozelkategori+''''

    You need the extra quotes to get the quotes in to dynamic sql.

    If you replace execute(@SQL) with select @sql then you get to see what your SQL statement looks like before executing it and therefore should be easy to identify any issue.

    Regards,

    Ian.

  • Thank you Ian.

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

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