1

I 'm not a regular of Sybase ASE.

Tring to make a script to add line into a tempory table.

sybase version 12.5.4

BEGIN 
declare and init variable

--boucle
select * into #parTemp from Parution where 1=2
WHILE @dateCourante <= @dateFin
BEGIN
    select @dpart1=datepart(mm,@dateCourante)
    select @dpart2=datepart(dd,@dateCourante)
    select @dpart3=datepart(dw,@dateCourante)
    --si on est pas le 1er mai
    if @dpart1 <> 5 AND @dpart2 <> 1
    begin
        --id parution
        select @idPar = @idPar + 1
        select @idParChaine = convert(varchar(10),@idPar)

        --num parution
        select @numPar =  @numPar + 1
        select @numParChaine = convert(varchar(20),@numPar)

        --prix du jour courant
        if datepart(dw,@dateCourante)=6
            select @prixCourant = @prixVen
        else
            if datepart(dw,@dateCourante)=1
               select @prixCourant = @prixDim
            else 
               select @prixCourant = @prix
            end
        end

        insert into #parTemp values (@idParChaine,@dateCourante,@numParChaine,@nbPagination,@prixCourant,@poids,@parCompt,@parOJD,@resVal)
    end
    select @dateCourante = dateadd(dd,1,@dateCourante)      
END 
END

Errors i get :

Error code 156, SQL state ZZZZZ: Incorrect syntax near the keyword 'WHILE'.
Error code 156, SQL state ZZZZZ: Incorrect syntax near the keyword 'end.
Error code 156, SQL state ZZZZZ: Incorrect syntax near the keyword 'End'.

i really don't understand, thank for help.

Pierre

label55
  • 125
  • 7
  • 'declare and init variable' isnt valid syntax for a start you need to specify the name and type - see http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc00801.1510/html/iqrefso/X315717.htm Or should you have listed that section from your code? – Rich Campbell Aug 29 '18 at 11:24
  • @RichCampbell it's juste to skip the declaration and init of my variable in the script. Troubles are in the loop while. – label55 Aug 29 '18 at 11:38
  • @label55: the first error message says there's an issue near `WHILE`, which could mean something **before** or **after** the `WHILE`, and since the only thing **before** the `WHILE` is the illegal `declare and init variable` ... Rich has (rightly) commented on this as a potential issue; the fact that you've chosen to remove bits-n-pieces of your code ... and replace with illegal statements ... doesn't help so, either provide the complete/actual code or expect to get a lot of down votes by a) choosing to obfuscate the problem and then b) expecting us to **guess** what the problem may be ... – markp-fuso Aug 29 '18 at 12:00
  • 1
    ... in the meantime ... `if / then / end if` is not the correct [if/then construct in ASE's T-SQL language](http://infocenter.sybase.com/help/topic/com.sybase.infocenter.dc36272.1570/html/commands/X74736.htm) – markp-fuso Aug 29 '18 at 12:04
  • @markp I have edit the line just before the while in my post. I have correct mistake with "if". – label55 Aug 29 '18 at 12:46
  • not sure what you corrected with the `if` constructs, but it's still wrong; have you looked at that link? there is no `then`, there is no `elseif`, there is no `end if` – markp-fuso Aug 29 '18 at 12:54
  • corrected completely, for the while trouble it's the "select * into #" – label55 Aug 29 '18 at 13:22
  • or there could be a problem with what comes before the `select into` ... so we're back to the previous issue ... an incomplete/obfuscated example to work with .... – markp-fuso Aug 29 '18 at 15:11
  • 1
    You still look to have too many end statements in that code assuming you've updated it to the latest. A normal if statement does not need an end unless you have a begin/end block. – Rich Campbell Aug 31 '18 at 08:42

0 Answers0