Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

SQL query with User input

Hi,
Is there a way to write sql query with user input.
Cheers
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

this question is a bit vague, as the issue is: how is the user finally running the sql?
ms sql management studio?
some home-grown app (which programming language)?
using a .sql file?
somehow else?
Can you give more details
Avatar of RIAS

ASKER

I need to save a sql query in database which first tries to  execute before it saves in database.
There are some values in query which will be user input later.
Example query is :
select * from Personal_Details a
inner join DEATH_BENEFIT b on
a.REFNO=b.REFNO

inner join PENSIONER_DETAIL c on
c.REFNO=a.REFNO

inner join TRANSFER_OUT_HISTORY d on
d.REFNO=a.REFNO

where (a.CURRStatus in ('Active','PreservedPensioner','Pensioner','Widow','Child'))
or (a.CURRStatus = 'No Liability'
and ((a.Dateleft > dateadd(y,17/06/2011,-1)) or  (b.dbdate > dateadd(y,17/06/2011,-1))  
or (c.pdpencomm  > dateadd(y,17/06/2011,-1)) or (d.topaid > dateadd(y,17/06/2011,-1))))

bold are the user input.
For the timebeing just need to replace it with user input.

Cheers
Do you mean you want the person running the script (in Management Studio or wherever) to be prompted for parameters at runtime, or just want to know how to use variables?
Avatar of RIAS

ASKER

Hi,
Just want to know how to use variables.

Cheers
ASKER CERTIFIED SOLUTION
Avatar of smu95rp
smu95rp
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Cheers mate!!