Thursday, March 25, 2010

Select statement to Extract text file in a column and to save images

0 comments
1. Text File in a column
Select statement can be utilized as to select data from a text file in a single column where 1 is as ID, Asia as region and the last column will contain the data from a text file.
SELECT 1 AS ID, 'ASIA' AS REGION, *
FROM OPENROWSET ( BULK 'C:\mysql.TXT',SINGLE_CLOB) AS MYTABLE
in the OPENROWSET parenthesis replace the path with your text file path.
Save an image in a binary format
Following query will save picture in sql db in binary format.

UPDATE CompanyInfo SET Logo = A.BulkColumn FROM
(SELECT * FROM OPENROWSET(BULK N'C:\Image\abc.jpg', SINGLE_BLOB) B) A

Things to consider when executing.
1. Place Power Link image somewhere at client database server’s machine.
2. Replace C:\Image\abc.jpg with the physical image path.
3. Check CompanyInfo table that it contains a record.
4. Execute above script to update image for that record.

0 comments: