Solved

Use string as SSRS table name

Posted on 2012-12-28
6
408 Views
Last Modified: 2013-01-02
I have a data source that is a folder filled with daily txt files.  Everyday I want to be able to automatically read yesterday's file.  In Report Services if I use the following code I am able to see the contents of a file.  
SELECT        *
FROM            12272012.txt

In SSMS if I use this code...
SELECT replace(convert(varchar, DATEADD(d, -1,getdate()), 101), '/', '') + '.txt' as ErrLog

It produces the file name I need (Ex: 12272012.txt) but it doesn't work in the FROM statement of SSRS.   Please help me with how I need to change this to make it work in SSRS?
SELECT *
FROM replace(convert(varchar, DATEADD(d, -1,getdate()), 101), '/', '') + '.txt'
0
Comment
Question by:BobRosas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Assisted Solution

by:venk_r
venk_r earned 150 total points
ID: 38729183
try using a stored procedure instead

 CREATE PROCEDURE myDynamic

AS

DECLARE @SQL NVARCHAR(4000)
DECLARE @table NVARCHAR(100)
SET @table =replace(convert(varchar, DATEADD(d, -1,getdate()), 101), '/', '') + '.txt'

SET @SQL='SELECT * FROM '+@Table

EXEC(@SQL)
0
 

Author Comment

by:BobRosas
ID: 38733423
Thank you for your help but if I do that I'm not sure how to access the sp.  Currently the data I need to access is a text file so my DataSource is an ODBC connection.  I don't know how to use my ODBC Data source connection and then connect to the sp.  Should I be doing this an entirely different way?
0
 
LVL 27

Expert Comment

by:planocz
ID: 38734594
One thing you may want to look at; is made your txt files into XML (layout) file.
since SSRS are just readable XML files.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:BobRosas
ID: 38737875
Thank you for your input!  Is there a place I can go to read more about how to do this?  Or can you provide me with more details?  I would still need to be able to automatically update the txt file to an xml file and I don't know how to do that.
0
 
LVL 27

Accepted Solution

by:
planocz earned 150 total points
ID: 38737940
you  will need to most likely do it in VB or C# coding. Their is a standard import file from the framework that has all the info to make and read a XML file. It  would be too much detail work to post here. you may want to get a code book or look online to "How to create and read XML files".
0
 

Author Comment

by:BobRosas
ID: 38738465
I've increased points so I can award to both since I'm not sure how I will proceed.  Thank you for your help!
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question