SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


prompt user for values with t-sql


prompt user for values with t-sql

Author
Message
icampbell
icampbell
SSC Journeyman
SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)

Group: General Forum Members
Points: 94 Visits: 277
Can i amend the following script to prompt a user for values when it is executed.

Declare @FROM_DATE datetime
Declare @TO_DATE datetime
Declare @ACAD_YEAR varchar(5)
Declare @COURSE varchar(10)
Declare @BLOCK varchar(1)




SELECT dbo.srs_sce.sce_ayrc, dbo.srs_sce.sce_crsc, dbo.srs_crs.crs_name, dbo.srs_sce.sce_blok, dbo.srs_sce.sce_occl, dbo.srs_sce.sce_scjc,
sab.sab_total, dbo.ins_stu.stu_surn, dbo.ins_stu.stu_fnm1, dbo.ins_stu.stu_fnm2, dbo.ins_stu.stu_fnm3
FROM dbo.srs_sce INNER JOIN
dbo.srs_crs ON dbo.srs_sce.sce_crsc = dbo.srs_crs.crs_code INNER JOIN
dbo.ins_stu ON dbo.srs_sce.sce_stuc = dbo.ins_stu.stu_code LEFT OUTER JOIN
(SELECT sab_stuc, COUNT(sab_stuc) AS sab_total
FROM dbo.srs_sab
WHERE (sab_begd >= @FROM_DATE) AND (sab_begd <= @TO_DATE)
GROUP BY sab_stuc) AS sab ON sab.sab_stuc = dbo.srs_sce.sce_stuc
WHERE (dbo.srs_sce.sce_ayrc = @ACAD_YEAR) AND (dbo.srs_sce.sce_crsc = @COURSE) AND (dbo.srs_sce.sce_blok = @BLOCK) AND
(sab.sab_total IS NOT NULL)
ORDER BY dbo.srs_sce.sce_blok, dbo.srs_sce.sce_occl, dbo.ins_stu.stu_surn, dbo.ins_stu.stu_fnm1, dbo.ins_stu.stu_fnm2, dbo.ins_stu.stu_fnm3:-P
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35658 Visits: 11361
Convert it to a stored procedure and pass the required parameters through it.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)

Group: General Forum Members
Points: 98553 Visits: 33014
And when you make the query into a procedure as Paul says, make the parameters NOT NULL and the users will have to supply them.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35658 Visits: 11361
Grant Fritchey (3/12/2010)
And when you make the query into a procedure as Paul says, make the parameters NOT NULL and the users will have to supply them.

Good point Grant - though I think you mean 'do not specify a default value'. :-)



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
icampbell
icampbell
SSC Journeyman
SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)SSC Journeyman (94 reputation)

Group: General Forum Members
Points: 94 Visits: 277
Thanks guys i'll give that a try and let you know how i get on.

Oh! How i miss the ease of doing PL/SQL
Paul White
Paul White
SSC-Dedicated
SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)SSC-Dedicated (35K reputation)

Group: General Forum Members
Points: 35658 Visits: 11361
icampbell (3/12/2010)
Oh! How i miss the ease of doing PL/SQL

Swings and roundabouts. Let's not go down that road eh?

BTW Excel can prompt for input Laugh



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Grant Fritchey
Grant Fritchey
SSC Guru
SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)

Group: General Forum Members
Points: 98553 Visits: 33014
Paul White (3/12/2010)
Grant Fritchey (3/12/2010)
And when you make the query into a procedure as Paul says, make the parameters NOT NULL and the users will have to supply them.

Good point Grant - though I think you mean 'do not specify a default value'. :-)


Yeah, that's the much more correct way to phrase it, of course.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search