Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 user input data in T-sql

Author  Topic 

svicky9
Posting Yak Master

232 Posts

Posted - 2005-08-20 : 10:10:12
Hi there

I want to give dynamic input to the t-sql code in sql analyzer.how do i do that....

Like adding 2 numbers

declare @a integer,@b integer,@c integer
--I dont want to give like this
--set @a = 5
--set @b = 10
set @c = @a + @b

can anyone help me with this

regards
Vic

Vicky

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-08-20 : 12:11:49
You could use a stored procedure or a function

eg

CREATE PROCEDURE YourProc @a int, @b int
AS
SELECT @a + @b AS YourResult


Then run like this

EXECUTE YourProc 5, 10


Returns:

YourResult
----------
15


Andy


Beauty is in the eyes of the beerholder
Go to Top of Page

svicky9
Posting Yak Master

232 Posts

Posted - 2005-08-21 : 18:26:08
i want the sql server to ask me values...like
Enter the value of a
Enter the value of b

and so on ...

Is there any way of doing that

thank you

Vicky
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-22 : 01:20:10
This thing is the presentation layer issue
If you want to do this in SQL Server, the only way is to run sp with different parameters
like

EXECUTE YourProc 5, 10
EXECUTE YourProc 13, 156
EXECUTE YourProc -7, 810



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -