0

I will reform my question because I realised that it was wrong.I will try to ask this as simple as I can:

 read file.txt
    exec @program //a query
      if(@program = 0)
        write file.txt + "OK;"
      else
        write file.txt + "NOK;"

My file.txt will contain:

123; 1;

124; 2;

125; 3;

Presuming my query verifies each of the numbers on the first column and returns 0 if its valid and something else if its not ,how can I tell it if @program = 0 write a OK; in the file at the end of the row and if its something else than 0 it will write NOK; so it will look something like this:

123; 1;OK;

124; 2;NOK;

125; 3;OK;

John Pietrar
  • 513
  • 7
  • 19
  • Share your queries, please. – Pirate X Jun 30 '16 at 05:48
  • So you only gave us a picture on notepad++. How about showing us the tables in database? We could understand your words more. –  Jun 30 '16 at 05:49
  • the table in the database is just a column containing 1181,1182,1184 – John Pietrar Jun 30 '16 at 05:51
  • Pasting in plain text is almost always way, way better than inserting screenshots. Images can't be indexed, copied or pasted, and are hostile to those that use a screen reader. What you have here is a trivial amount of text that should be easy to transpose. – tadman Jun 30 '16 at 06:40

1 Answers1

1

It looks like your data has a primary key, If I we're you I'd go row by row reading the row to be inserted from your file, then doing a select on the database to see if its arrived in the table, then adding adding the 'OK' / 'NOK' value to end of the row in the text file.

Regards,

James

James Scott
  • 1,032
  • 1
  • 10
  • 17
  • and how do you add at the end of the row in the text file in sql?Do you use something like `set @path = ' ' set @text = 'OK' EXEC WriteToFile @path, @text`? – John Pietrar Jun 30 '16 at 09:44
  • Thanks for the upvote John, what language are you using? I thought this was python but now I'm not so sure, is it a SQL derivative? – James Scott Jun 30 '16 at 10:41
  • I haven't used C# for years, but what you need is a stream reader and or a stream writer. Take a look at the streamReader [here](http://www.tutorialspoint.com/csharp/csharp_text_files.htm) and how to change a specific line [here](http://stackoverflow.com/questions/1971008/edit-a-specific-line-of-a-text-file-in-c-sharp). Are you loading large files? – James Scott Jun 30 '16 at 10:57
  • Then stream reader will be fine, if it was say over 10,000 rows per file then there would be memory overhead rewriting the whole file for each line, glad this doesn't apply. – James Scott Jun 30 '16 at 10:59
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/116083/discussion-between-james-scott-and-john-pietrar). – James Scott Jun 30 '16 at 11:12