HELP please on stord PROCEDURE

  • This is my stord PROCEDURE !

    i am not able to do the expression "IN"

    DECLARE @inmhlka VARchar(20)

    set @inmhlka= '3,4,6,7,8,9,10'

    SELECT Services

    FROM dbo.Revenue

    WHERE CONVERT(VARchar (20),Services) IN (CONVERT(VARchar(20), @inmhlka))

    -------------

    only when i put one expression "IN"

    set @inmhlka= '3'

    -----------------------

    it work HELP

    thnks

    ilan

  • When you use SET @inmhlka= '3,4,6,7,8,9,10', it is looking for the value '3,4,6,7,8,9,10' in the service field. That is why it works when you search for '3'.

    In this case,you need to piece together the SELECT statement, as shown below:

    DECLARE @inmhlka VARCHAR(20)

    DECLARE @exec_stat VARCHAR(100)

    SET @inmhlka= '3,4,6,7,8,9,10'

    SET @exec_stat = 'SELECT Services FROM dbo.Revenue WHERE CONVERT(VARchar (20),Services) IN (' + @inmhlka + ');'

    EXEC (@exec_stat)

    HTH

    Billy

  • thnks

    help agin

    ----------

    and if i have the code like this how can i put your code here

    -----------

    SELECT dbo.Table1.Field1, dbo.Revenue.Services

    FROM dbo.Revenue INNER JOIN

    dbo.Table1 ON dbo.Revenue.Services = dbo.Table1.Field1

    WHERE (dbo.Revenue.Services IN (1, 2, 3, 4))

    ORDER BY dbo.Table1.Field1

  • DECLARE @inmhlka VARCHAR(20)

    DECLARE @exec_stat VARCHAR(1000)

    SET @inmhlka= '1,2,3,4'

    SET @exec_stat = 'SELECT dbo.Table1.Field1, dbo.Revenue.Services FROM dbo.Revenue INNER JOIN dbo.Table1 ON dbo.Revenue.Services = dbo.Table1.Field1 WHERE (dbo.Revenue.Services IN (' + @inmhlka + ')) ORDER BY dbo.Table1.Field1;'

    EXEC (@exec_stat)

  • problem with the code

    ---------

    Server: Msg 208, Level 16, State 1, Line 1

    Invalid object name 'dbo.Revenue'.

    Server: Msg 208, Level 16, State 1, Line 1

    Invalid object name 'dbo.Table1'.

    ------------------------

    thnks agin ilan

  • forgiveness the code is ok

    thnks agin for your help

    ilan

Viewing 6 posts - 1 through 5 (of 5 total)

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