Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2018, 04:51 PM
Jung Jung is offline
Junior Member
 
Join Date: Oct 2014
Posts: 27
Default Building SQL string

Hello,

I build SQL string in the fly which is well executed but with no data I need please, someone to tell me is my sql string is correct I use UIB to connect Firebird DB:

Code:
V1:='SELECT FIRST :NBROW * FROM VW_MVT_LIV_FOURNISSEUR WHERE MVT_ID>=:NextRow AND MVT_ID<=:EndRow';
Qry.SQL.Clear;
Qry.SQL.Text:=V1;
Qry.Params.ByNameAsInteger['NBROW']:=NbRow;
Qry.Params.ByNameAsInteger['NEXTROW']:=NextRow;
Qry.Params.ByNameAsInteger['ENDROW']:=EndRow;
Qry.Open;
Is executed without data

But if I do that without using parameters :

Code:
V1:='SELECT FIRST '+INTTOSTR(NBROW)+' * FROM VW_MVT_LIV_FOURNISSEUR WHERE MVT_ID>='+INTTOSTR(NextRow)+ ' AND MVT_ID<='+INTTOSTR(EndRow);
I get data
Can you please help me ?

Last edited by Jung; 01-30-2018 at 06:33 PM.
Reply With Quote
  #2  
Old 01-30-2018, 09:21 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 304
Default

You might try

V1:='SELECT FIRST '+NBROW+' * FROM VW_MVT_LIV_FOURNISSEUR WHERE MVT_ID>='+NextRow+'AND MVT_ID<='+EndRow;

or something along this line. V1 must be a text line. Can't have embedded values within it.

Also your NBROW etc must be declared before you assign V1.
Reply With Quote
  #3  
Old 01-31-2018, 09:10 AM
Jung Jung is offline
Junior Member
 
Join Date: Oct 2014
Posts: 27
Default

Hello

The problem is to use query parameters which doesn't work for me using your string need the ':' for parameters. NBROW, NEXTROW, ENDROW are already declared
Reply With Quote
  #4  
Old 01-31-2018, 04:00 PM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 187
Default

You can't use parameters in the SELECT portion of a query. You'll have to concatenate that portion of the query, then you can use parameters for the WHERE portion of the query.
Code:
V1 := 'SELECT FIRST ' + INTTOSTR(NBROW) + ' * FROM VW_MVT_LIV_FOURNISSEUR WHERE MVT_ID >= :NextRow AND MVT_ID <= :EndRow';
You can also rewrite the query using the BETWEEN condition
Code:
V1 := 'SELECT FIRST ' + INTTOSTR(NBROW) + ' * FROM VW_MVT_LIV_FOURNISSEUR WHERE MVT_ID BETWEEN :NextRow AND :EndRow';
Reply With Quote
  #5  
Old 01-31-2018, 06:10 PM
Jung Jung is offline
Junior Member
 
Join Date: Oct 2014
Posts: 27
Default

Thanks rojam but your solution doesn't work
Anyway I left this method for another because I haven't much time.
Thank you very for all
Reply With Quote
  #6  
Old 01-31-2018, 10:32 PM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 304
Default

I have been using PHP prepared statements. Not sure if anything can be transposed into Delphi.

https://www.w3schools.com/php/php_my...statements.asp
Reply With Quote
  #7  
Old 02-01-2018, 09:04 AM
Jung Jung is offline
Junior Member
 
Join Date: Oct 2014
Posts: 27
Default

I will compare it with delphi thank Marsheng
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:52 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.