Home > Back-end >  The variables in the form of expression about SQL statements
The variables in the form of expression about SQL statements

Time:09-24

ADOQuery_sbcx. SQL. Text:='SELECT yqmc, count (*) FROM [ZHXT] [dbo] [SBGL] where left ([yqmc], I)=' "+ Adoquery2. FieldByName (' yqmc). The value +" 'group by yqmc


If the above statement, I is a variable, so it is wrong to write directly, excuse me how should express the I variable,

Is "" + I +" "?? If that is wrong

CodePudding user response:

"' + I +" 'three quotes on, try it

CodePudding user response:

Do not recommend using splicing SQL statements, convert the Format function

 
ADOQuery_sbcx. SQL. Text:=Format (' SELECT yqmc, count (*) FROM [ZHXT] [dbo] [SBGL] where left ([yqmc], % d)=% s group by yqmc ', [I, QuotedStr (Adoquery2. FieldByName (' yqmc). AsString) are identical]);

CodePudding user response:

String to use QuotedStr, looks much more pleasing to the eye
ADOQuery_sbcx. SQL. Text:='SELECT yqmc, count (*) FROM [ZHXT] [dbo] [SBGL] where left ([yqmc], I)=' +
QuotedStr (Adoquery2 FieldByName (' yqmc). The value) +
'group by yqmc'

CodePudding user response:

ADOQuery_sbcx. SQL. Text:='SELECT yqmc, count (*) FROM [ZHXT] [dbo] [SBGL] where left ([yqmc],' + inttostr (I) + ')='" + Adoquery2. FieldByName (' yqmc). The value + "' group by yqmc

CodePudding user response:

"' +! + "'

CodePudding user response:

ADOQuery_sbcx. SQL. Text:='SELECT yqmc, count (*) FROM [ZHXT] [dbo] [SBGL] +'
'where the left ([yqmc],' + InttoStr (I) + ')='+
QuotedStr (Adoquery2 FieldByName (' yqmc). AsString) are identical + 'group by yqmc'

CodePudding user response:

refer to the second floor CZP98168 response:
by joining together the SQL statement, is not recommended to switch to the Format function

 
ADOQuery_sbcx. SQL. Text:=Format (' SELECT yqmc, count (*) FROM [ZHXT] [dbo] [SBGL] where left ([yqmc], % d)=% s group by yqmc ', [I, QuotedStr (Adoquery2. FieldByName (' yqmc). AsString) are identical]);


This is good
  • Related