SQL Server - stored procedure(correct the query)

Asked By Rohini Kuchadi
10-Feb-12 05:17 AM
Hi this is the query which i have given in he stord procedure.to get start time, duration,title,movie etc from the database.

SELECT   AIRPLAY.start_time AS AIRTIME, DATEDIFF(S,AIRPLAY.start_time, AIRPLAY.end_time) AS DURARATION, Titles.name AS SONG, Artists.name AS ARTISTorMOVIE
FROM     Songs INNER JOIN
            Titles ON Songs.title_id = Titles.title_id INNER JOIN
            Artists ON Songs.artistID = Artists.artistID CROSS JOIN
            AIRPLAY INNER JOIN
            STATIONS ON AIRPLAY.station_id = STATIONS.station_id INNER JOIN
            PRODUCTIVITY ON AIRPLAY.start_time = PRODUCTIVITY.start_time WHERE STATIONS.station_id=@stationid AND
            AIRPLAY.segment_type_id=1 AND AIRPLAY.start_time>@startNoEarlierThan and AIRPLAY.end_time<@endNoLaterThan and PRODUCTIVITY.new_title_id=Songs.title_id
order by AIRPLAY.start_time asc


Soppose in the textboxes if give the dates like this 'start date = 2010-09-09' and 'enddate = 2010-09-11'. It should show me the recordes present in between these dates.

But it is not showing me like that.if am giving the dates which i have mentioned above then only it is records that are present. If i give any other dates it is showing me the result as '0'
  Reena Jain replied to Rohini Kuchadi
10-Feb-12 05:23 AM
hi,

if you want to retrieve  records between some date then you must have 2 date wheres between you want the date, in this case you can use (> and <) symbol as well as between

here is the query

Select * from table1 where Convert(datetime, mydate, 103)  between
Convert(datetime, @Fromdt, 103) and Convert(datetime, @Todt, 103)

try this and let me know
  Web Star replied to Rohini Kuchadi
10-Feb-12 05:58 AM
In the Sql query if you are filter result on datetime column than you must consider the column datatype should be datetime than only work properly.



Create New Account
help
How can I decrypt a SQL Server stored-procedure? SQL Server hi Please help on this How can I decrypt a SQL Server stored-procedure? thx guru SQL Server Programming Discussions SQL Server (1) Stored procedure (1) Stu (1
Can't login to SQL Server SQL Server Hello, I'm trying to migrate one SQL Server 2000 database to SQL Server Express, and I'm having the following issue. In the SQL Server 2000 database I
Accessing data on a server? SQL Server I have SQL Server developer edition installed on one computer and SQL Server Express Edition install on another computer. When I try to "Attach" a database located on my file server, SQL Server does not "see" the network drive. Is there anyway to get a local
Additonal thoughts, you should be able to connect to SQL Server via SQL Server SQL Server Additonal thoughts, you should be able to connect to SQL Server via SQL Server Management Studio. This will provide you with whether or not SQL Server
Alias for Linked SQL Server? SQL Server Hi, I'm trying to connect to a linked SQL Server 2008 from my local SQL = Server 2008. Everything seems to work fine so far but I'm having the following = problem