Saturday, February 25, 2012

Adding images with SQL Server Express Management Studio

Can I add images to a table with SQL Server Express Management Studio? If so, how, if not, what alternative methods other than the point-and-click can I use?

Thanks in advance,

Fedor Steeman

hi Fedor,

there's no "point and click" solution for your requirement in SSMS... but you can "load" a column executing the appropriate Transact-SQL statement..

something like

SET NOCOUNT ON;

USE tempdb;

GO

CREATE TABLE dbo.TestTB (

Id int NOT NULL PRIMARY KEY,

img varbinary(MAX) NULL

);

GO

PRINT 'retrieve the img from file';

DECLARE @.img varbinary(MAX);

SET @.img = (

SELECT Q.BulkColumn

FROM OPENROWSET(BULK 'D:\MVPLogo.gif', SINGLE_BLOB) AS Q

);

SELECT CONVERT(varchar(MAX),@.img);

PRINT 'then you can insert it into the desired table';

INSERT INTO dbo.TestTB VALUES ( 1 , @.img );

SELECT * FROM dbo.TestTB;

GO

DROP TABLE dbo.TestTB;

--<

retrieve the img from file

--

GIF89as ′ ? 4:u???jt£CJ?K{abridged}

then you can insert it into the desired table

Id img

--

1 GIF89as ′ ? 4:u???jt£CJ?K{abridged}

and that's it..

regards

No comments:

Post a Comment