Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

prompt user for values with t-sql Expand / Collapse
Author
Message
Posted Friday, March 12, 2010 4:33 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 08, 2012 5:56 AM
Points: 40, 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
Post #881635
Posted Friday, March 12, 2010 4:50 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:04 PM
Points: 11,168, Visits: 10,933
Convert it to a stored procedure and pass the required parameters through it.



Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #881648
Posted Friday, March 12, 2010 6:21 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:48 AM
Points: 14,802, Visits: 27,278
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #881695
Posted Friday, March 12, 2010 9:06 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:04 PM
Points: 11,168, Visits: 10,933
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
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #881881
Posted Friday, March 12, 2010 9:18 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 08, 2012 5:56 AM
Points: 40, 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
Post #881898
Posted Friday, March 12, 2010 9:23 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:04 PM
Points: 11,168, Visits: 10,933
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




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #881907
Posted Friday, March 12, 2010 9:52 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 4:48 AM
Points: 14,802, Visits: 27,278
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 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #881936
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse