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
 Select With Step Through and WaitFor

Author  Topic 

abrown72
Starting Member

4 Posts

Posted - 2013-06-06 : 16:41:52
My SQL level of knowledge is maybe somewhere around an intermediate level.

I’ve come across a need to display some rows of data and for display purposes I’d like to implement a couple of SQL commands I’ve come across in my research but I have no clue how to write this sql statement so I came here looking for help.

I have a basic table of some company information that is grouped by department like so.

Id (int)(incremental)
Department (nvarchar20)
Message(text)
Duration(int)(in seconds)
Active(bit)

What I’m looking for is:

Select Message, Duration Where (Department = ‘department’) AND (Active = ‘True’)

Then I would like to take this one step further. Is there a way to have the sql server step through each qualifying record (might be 5-10 messages per department) output the Message and in each record set a WAITFOR timer that gets its duration from the current record being displayed? then on to the next record until the end is reached? Then programmatically I'd just have it repeat. This way if there are any changes in the messages whenever the end is reached and the loop starts at record 1 again new updates take effect.

Thanks for the help!

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-06-06 : 17:26:50
The first part, if I understood you correctly, is easy:
SELECT Message, Duration
FROM YourTable
WHERE Department = 'YourDepartmentNameHere'
AND Active = 1;
If you need more columns to be displayed, just add them comma-separated in the list after the SELECT keyword.

SQL Server is not designed to serve as a friendly GUID interface, so the second bit that you want to do is best done using some other technology - perhaps a .Net program, or an Access front end or something similar.
Go to Top of Page

abrown72
Starting Member

4 Posts

Posted - 2013-06-06 : 18:49:34
Thanks for the reply, I completely understand select statements even though mine above was wrong, and yes I could likely code this in vb/asp.net.

I was looking more for the WaitFor syntax, and the syntax of stepping through the returning records. If it is possible at all.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-07 : 01:57:50
sorry didnt understand why you want waitfor.
can you elaborate on this?

Is there a way to have the sql server step through each qualifying record (might be 5-10 messages per department) output the Message and in each record set a WAITFOR timer that gets its duration from the current record being displayed?

In any case sql server wont be displaying any data to user directly. you do that part in front end

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -