Showing posts with label contents. Show all posts
Showing posts with label contents. Show all posts

Monday, March 19, 2012

Help Needed With Simple Case Statement in SQL

Hello,

I am looking to modify this Case Statement. Where it says ELSE '' I need it to display the actual contents of the cell. 1 = Yes , 0 = No, (any other integer) = actual value.

Right now if the value is anything other than 1 or 0, it will leave the cell blank.

CASE dbo.Training.TrainingStatus WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' ELSE '' END AS TrainingStatus

Thank You.

Try something like this:

CASE dbo.Training.TrainingStatus WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' ELSE CAST(dbo.Training.TrainingStatus AS varchar(20)) END AS TrainingStatus

Help needed with importing text files

I have a load (180,000+) of text files whose contents need to go into a SQL server database.
Whats the best way of doing this? Using a c# console program and if so, using FileStream or StreamReader? Or using a feature of SQL server itself. The text files themselves are less that 1k and are literally less than 200 characters.
The problem is, I've tried a WinForm and although I can detect what files are there, as soon as I attempt to open one for reading, everything stops working and won't insert anything to the database.

Try this link to use DTS with BCP(bulk copy). Hope this helps.
http://www.sqldts.com/default.aspx?237