Click here to Skip to main content
15,991,109 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am reading two different text files, one file reads the transaction ID and runs the query below to match the text file record. The other text file checks for Customer ID and runs this same query as well. What I need to do is build maybe a stringbuilder? So when it runs the Transaction textfile it elimates the "CustomerID IS NOT NULL" from the where clause.

What I have tried:

private DataRowCollection ExtractData(DateTime DailyFileDate)
       {
           Log.Info("Querying Microbilt data...");

           string sql = string.Empty;

           {
           sql = @"
                           SELECT
                               TransID,
                               CustomerID,
                               RID,
                               FileDate
                           FROM
                           (
                               SELECT TransID AS TransID,
                               CustomerID,
                               RID,
                               FileDate,
                               ROW_NUMBER() OVER(PARTITION BY TransID ORDER BY TransID DESC) AS RN
                               FROM MicroBilt.dbo.TransIDIgnoreAudit
                               WHERE FileDate BETWEEN @FileDate AND DATEADD(D,1, @FileDate AND CustomerID IS NOT NULL
                           ) A
                           WHERE RN = 1";
Posted
Updated 24-Feb-17 7:39am
Comments
[no name] 24-Feb-17 13:15pm    
You would probably be better off writing a stored procedure.
SmartDeveloping 24-Feb-17 13:17pm    
No, because this gets loaded into a dictionary.
Maciej Los 24-Feb-17 13:28pm    
:laugh:
A stored procedure returns data, which you can load into Dictionary object.
Your login is: SmartDeveloping, so you have to be smart to develop your application.
[no name] 24-Feb-17 15:13pm    
What does that have to do with anything?
Bryian Tan 24-Feb-17 13:44pm    
i think the code is missing a closing tag ) in DATEADD(D,1, @FileDate -- should be DATEADD(D,1, @FileDate) AND ... ?

1 solution

As NotPoliticallyCorrect[^] mentioned, you have to use stored procedure(s)[^].
See: Walkthrough: Using Only Stored Procedures (C#)[^]

By the way...
You can upload data directly from text file into datatable[^] object using ADO.NET[^].
See:
Much ADO About Text Files[^]
Schema.ini File (Text File Driver) | Microsoft Docs[^]

Check my past answer: Read Text File Specific Columns[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900