Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

SP problem

Hi All,

I have SP with script below :

  SET @SCRIPT = @SCRIPT + ' WHERE CONVERT(Char(8), A.TglJurnal, 112) '
         SET @SCRIPT = @SCRIPT + ' BETWEEN ' + CONVERT(Char(8), @FromDate , 112)  
         SET @SCRIPT = @SCRIPT + ' AND ' + CONVERT(Char(8), @ToDate , 112)

         SET @SCRIPT = @SCRIPT + ' AND A.BuktiJurnal = ' +  @BuktiJurnal

The result :

WHERE CONVERT(Char(8), A.TglJurnal, 112)  
BETWEEN 20180101 AND 20180131
AND A.BuktiJurnal = BK 0023/YSL/2017/I/18

No apostrophe at the date and string variable.

What's wrong with the script ?

Thank you.
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of emi_sastra
emi_sastra

ASKER

Hi Jim,

- Also of course what's the point of using @script as dynamic T-SQL?  Unless there is a hard reason to use dynamic sql, better to avoid it and make it a straight SQL statement.

Please see the attached Sql Script.

Any suggestion are welcom.

Thank you.
ERV_SP_Print_Ledger_Detail_Jurnal.sql
Hi Jim,

Hi Jim,

Where to put UNION ALL from the SQL Script I attached ?


USE [YSL_TRADING]
GO

DECLARE      @return_value int

EXEC      @return_value = [dbo].[ERV_SP_Print_Ledger_Detail_Jurnal]
            @FromDate = '2018/01/01',
            @ToDate = '2018/02/28',
            @FromAccNo = NULL,
            @ToAccNo = NULL,
            @LawanAccNo = NULL,
            @ListAccNo = NULL,
            @BuktiJurnal = ' '

--SELECT      'Return Value' = @return_value

GO

Thank you.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi All,

Thank you very much for your help.