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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query DB by date w/ results to table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 04/22/2014 :  08:04:55  Show Profile  Reply with Quote
I'm a bit of a SQL newb but have been tasked with coming up with some code to retrieve values from a historian database. I'm retrieving the name of an object (tag) and its value at a specific time every month of the year. However, the year will be user defined parameter coming from a report. So if the user selects 2014 it should query on 1/1/2014,2/1/2014 and so on.

I came up with the simple part of the query which is looking up the tag names and associated values:

SELECT Tagname,value
From runtime.dbo.History
WHERE Tagname IN ('Tag1', 'Tag2')
and wwVersion = 'Latest'
and DateTime = @Date

Here are the issues I need to solve:
1. I can manually set the @Date but I'd like to have it do whats described above. I'm thinking some type of loop might be used?
2. I'm not sure how to output it into table format to look like:

Tag 1, (jan value), (feb value), (mar value), etc...
Tag 2, (jan value), (feb value), (mar value), etc...

Any help would be appreciated. Thanks!
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000