Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL query with User input

Posted on 2011-09-22
7
Medium Priority
?
251 Views
Last Modified: 2012-05-12
Hi,
Is there a way to write sql query with user input.
Cheers
0
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36579740
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?
0
 
LVL 6

Expert Comment

by:kswathi
ID: 36579743
Can you give more details
0
 

Author Comment

by:RIAS
ID: 36579811
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:smu95rp
ID: 36580003
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?
0
 

Author Comment

by:RIAS
ID: 36580408
Hi,
Just want to know how to use variables.

Cheers
0
 
LVL 2

Accepted Solution

by:
smu95rp earned 2000 total points
ID: 36580496
OK

Declare @RefDate datetime

Set @RefDate = '17/06/2011'

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, @RefDate, -1))
    Or  (b.dbdate > dateadd(y, @RefDate, -1))  
    Or (c.pdpencomm  > dateadd(y, @RefDate, -1)) Or (d.topaid > dateadd(y, @RefDate, -1)))
)
0
 

Author Closing Comment

by:RIAS
ID: 36595904
Cheers mate!!
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question