可以的 例如: SQL: declare @a varchar(10) set @a=convert(varchar(10),getdate(),120) select * from table where convert(varchar(10),datetime,120)=@a
Using parameters at runtimeWith some datasets, if the name of the stored procedure is not specified until runtime, no TParam objects are automatically created for parameters and they must be created programmatically. This can be done using the TParam.Create method or the TParams.AddParam method:var P1, P2: TParam; begin ... with StoredProc1 do begin StoredProcName := 'GET_EMP_PROJ'; Params.Clear; P1 := TParam.Create(Params, ptInput); P2 := TParam.Create(Params, ptOutput); try Params[0].Name := 'EMP_NO'; Params[1].Name := 'PROJ_ID'; ParamByname('EMP_NO').AsSmallInt := 52; ExecProc; Edit1.Text := ParamByname('PROJ_ID').AsString; finally P1.Free; P2.Free; end; end; ... end;Even if you do not need to add the individual parameter objects at runtime, you may want to access individual parameter objects to assign values to input parameters and to retrieve values from output parameters. You can use the dataset's ParamByName method to access individual parameters based on their names. For example, the following code sets the value of an input/output parameter, executes the stored procedure, and retrieves the returned value:with SQLStoredProc1 do begin ParamByName('IN_OUTVAR').AsInteger := 103; ExecProc; IntegerVar := ParamByName('IN_OUTVAR').AsInteger; end;
例如:
SQL:
declare @a varchar(10)
set @a=convert(varchar(10),getdate(),120)
select * from table where convert(varchar(10),datetime,120)=@a
P1, P2: TParam;
begin
...
with StoredProc1 do begin
StoredProcName := 'GET_EMP_PROJ';
Params.Clear;
P1 := TParam.Create(Params, ptInput);
P2 := TParam.Create(Params, ptOutput);
try
Params[0].Name := 'EMP_NO';
Params[1].Name := 'PROJ_ID';
ParamByname('EMP_NO').AsSmallInt := 52;
ExecProc;
Edit1.Text := ParamByname('PROJ_ID').AsString;
finally
P1.Free; P2.Free;
end;
end;
...
end;Even if you do not need to add the individual parameter objects at runtime, you may want to access individual parameter objects to assign values to input parameters and to retrieve values from output parameters. You can use the dataset's ParamByName method to access individual parameters based on their names. For example, the following code sets the value of an input/output parameter, executes the stored procedure, and retrieves the returned value:with SQLStoredProc1 do
begin
ParamByName('IN_OUTVAR').AsInteger := 103;
ExecProc;
IntegerVar := ParamByName('IN_OUTVAR').AsInteger;
end;