Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Declaring variables in SQL select statement
Fri, Jan 24 2014 3:16 PMPermanent Link

Wayne Bignell

I am converting a program from MS SQL Server to ElevateDB.
In MS SQL select statements you can declare a variable at the top  and use it many times in the statement.
Is there a way in ElevateDB to do a similar thing or do you have to have a separate parameter each time you want to use the same  value.
Here is the MS SQL statement;

Declare @MN varchar(25)
Set @MN = :cKey
Select Top 80 dbo.fnCliCode(CLI_SHOP, CLI_ID) as CLIENT_CODE,
 FIRST,LAST, Mobile, PhoneH, PhoneW
From CLIENT_TBL
Where Deleted = 0
 and (MOBILE like @MN or
      PHONEH like @MN or
      PHONEW like @MN or
      FIRST like @MN or
      LAST like @MN or
      FIRST+' '+LAST like @MN)

Order by FIRST, LAST
Sat, Jan 25 2014 4:33 AMPermanent Link

Uli Becker

Wayne,

<<
I am converting a program from MS SQL Server to ElevateDB.
In MS SQL select statements you can declare a variable at the top  and
use it many times in the statement.
Is there a way in ElevateDB to do a similar thing or do you have to have
a separate parameter each time you want to use the same  value.
Here is the MS SQL statement;
>>

You have to use a script or a stored procedure.
Here a "translation" (though not tested at all):

SCRIPT
BEGIN

   DECLARE Result CURSOR WITH RETURN FOR Stmt;
   DECLARE MN VARCHAR(25);
   SET MN = 'Test%';

   PREPARE Stmt FROM
      'Select fnCliCode(CLI_SHOP, CLI_ID) as CLIENT_CODE,
       FIRST,LAST, Mobile, PhoneH, PhoneW
       From CLIENT_TBL
       Where Deleted = 0
       AND (MOBILE like ? or
       PHONEH like ? or
       PHONEW like ? or
       FIRST like ? or
       LAST like ? or
       FIRST + '' '' + LAST like ?)
       Range 1 TO 80';
   OPEN Result using MN,MN,MN,MN,MN,MN;

END

Uli
Sat, Jan 25 2014 7:09 AMPermanent Link

Wayne Bignell

Uli Becker wrote:

<<
I am converting a program from MS SQL Server to ElevateDB.
In MS SQL select statements you can declare a variable at the top  and
use it many times in the statement.
Is there a way in ElevateDB to do a similar thing or do you have to have
a separate parameter each time you want to use the same  value.
Here is the MS SQL statement;
>>

You have to use a script or a stored procedure.
Here a "translation" (though not tested at all):

Thanks very much Uli.
I have tested it and it worked fine. I have been using MS SQL for many years and
got into the habit of doing things their way. Looks like I have a lot to learn.

Thanks again Uli
Wayne
Image