Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Use string as SSRS table name

Posted on 2012-12-28
6
Medium Priority
?
433 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
  • 3
  • 2
6 Comments
 
LVL 8

Assisted Solution

by:venk_r
venk_r earned 600 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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 

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 600 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview

824 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