Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ask for a variable in a query 1

Status
Not open for further replies.

Michael57

Technical User
Nov 15, 2005
131
0
0
CA
In access you can ask the user to type in a variable when the query starts that will be used to execute the query. How is this done in sql
 
It can not be. T/SQL is not an interactive language. This would need to be handled by the front end that is used.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
You can't "ask the user to type in a value" in SQL Server. There's no front end. SQL Server is ALL back-end. The front end has to do the asking and pass the value to the server in a parameter or using constructed SQL.

Look up VB examples using the ADODB.Command object and parameters, with the parameters in the query represented by question marks, ala

"select * from Orders where OrderID = ?"

adocommand.parameters.add adocommand.createparameter("orderid", ..., 12345)

This is actually expanded to something like

exec sp_executesql N'select * from Orders where OrderID = @P1', N'@P1 int', 12345

Which brings up stored procedures

Code:
CREATE PROCEDURE SelectOrder @OrderID int
AS
select * from Orders where OrderID = @OrderID

Now go do some searches with Google. This information should be enough to get you started. You have a lot to learn, but the information you need is out there!

No one should have to tell you much more in this thread until you've studied a little and can ask more specific questions.

[COLOR=#aa88aa black]Cum catapultae proscriptae erunt tum soli proscript catapultas habebunt.[/color]
 
I use sharepoint. How is this done here?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top