473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

MSSQL Query Extracting Dates in Filename

benchpolo
142 100+
Sample A: Enrollment_20081211.txt
Sample B: Enrollment_20081211_01.txt

CODE
declare @date varchar(8)
, @cmd varchar(255)

set @date = REPLACE(CONVERT(VARCHAR,GETDATE()-1,111),'/','')

truncate table bow_flat
select @cmd ='BULK INSERT [1400_byte_layout].dbo.IKA_Flat FROM ''\\test\ArcadianEnrollment_'+@date+'.txt'''
exec (@cmd)

PROCESS
The code above BCP Sample A file into a table based on the current date @date, and this process is fine. But I am having issues with Sample B where the filename has an increment number before the .txt filename, I having difficulty modifying the code above to make it work for sample B.

Your assistance regarding this matter is aprpeciated.
Thanks.
Dec 12 '08 #1
3 2253
ck9663
2,878 Expert 2GB
Why not grab all the name of the files that are candidate for uploading, store it in a table, BULK INSERT each record.

-- CK
Dec 13 '08 #2
benchpolo
142 100+
ck that was my problem I don't know where to start. Also, the format of the file is PIPE delimited. I created a table to import the file, but how do i do it if i have multiple files. Import process is done by date dynamically as indicated in the text filename.

Thanks
Dec 13 '08 #3
ck9663
2,878 Expert 2GB
1. Use xp_cmdshell to grab all the files on a predetermined directory.
2. Store the result to a table.
3. Loop through the table and BULK INSERT each filename into a table with the same name. If you don't need th eactual table, use temp or variable tables and process as necessary. BULK INSERT has a parameter to define what delimiter to use.

-- CK
Dec 13 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Kukurydz | last post by:
I've got such problem: My database is stored on MSSQL Server. I have to write reports for it in MSAccess. I've got a problem with creating a query which will select records from MSSQL table with...
2
by: Ian Hinson | last post by:
Hi, Sometimes I find it handy to construct an sql string for action queries, and then run it directly against the database and/or connection instead of using Recordsets for simple updates. eg....
2
by: Dickyb | last post by:
Extracting an Icon and Placing It On The Desktop (C# Language) I constructed a suite of programs in C++ several years ago that handle my financial portfolio, and now I have converted them to...
2
by: jblankenburg | last post by:
Please help! I am hunting high and low for an equivalent function for MSSQL's DATENAME function. Here's the spec on the function from MSSQL's Books Online: DATENAME Returns a character...
1
by: detho | last post by:
Hi everyone... I am currently developing a streaming movie front-end for my companies' intranet. The script is done with PHP on the back-end and HTML and CSS for the front-end. Basically, the...
17
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script...
17
by: ukchat | last post by:
I.m creating a dynamic query to pull out workbooks from my database the table structure is below. Table: curricworkbooks Columns: ID, curric, assessment, topic, workbook, filename Example data...
4
by: poolboi | last post by:
hi guys i've having some problem extracting data from a text file example if i got a text file with infos like: Date 2008-05-01 Time 22-10 Date 2008-05-01 Time 21-00 Date 2008-05-02 Time...
2
by: akronymn | last post by:
I have an mssql database that I need to migrate to mysql. For some reason though any queries to any columns of type datetime are returned in French in the following format: 7/avr/2004 14:00 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.