Friday, March 9, 2012

save an image into a table using Query Analyzer

I have a table with two fields Part_num and Pic in SQL server 2000
Pic is of Image type. Is there a way I can save images for each part_num using Query analyzer?You can use BULK INSERT or bcp.

From BOL:

xp_cmdshell 'bcp pubs..bitmap in test.doc -Usa -Ppassword -Sservername'

--------------------
The Bcp.fmt file:

8.0
1
1 SQLIMAGE 0 5578 "" 1 c1

Using the BULK INSERT statement to bulk copy the Test.doc data file into the bitmap table in the pubs database, execute from a query tool, such as SQL Query Analyzer:

BULK INSERT pubs..bitmap FROM 'c:\test.doc'
WITH (
FORMATFILE = 'c:\Bcp.fmt'
)|||Sorry I'm new to this, Will this work if I have an image, lets say 150.bmp on C: drive? So would it be
BULK INSERT pubs..bitmap FROM 'c:\150.bmp'
WITH (
FORMATFILE = 'c:\150.bmp'
) ?

Originally posted by snail
You can use BULK INSERT or bcp.

From BOL:

xp_cmdshell 'bcp pubs..bitmap in test.doc -Usa -Ppassword -Sservername'

--------------------
The Bcp.fmt file:

8.0
1
1 SQLIMAGE 0 5578 "" 1 c1

Using the BULK INSERT statement to bulk copy the Test.doc data file into the bitmap table in the pubs database, execute from a query tool, such as SQL Query Analyzer:

BULK INSERT pubs..bitmap FROM 'c:\test.doc'
WITH (
FORMATFILE = 'c:\Bcp.fmt'
)|||Check this (I tested it):

BULK INSERT pictures FROM 'c:\tmp\bridge.jpg'
WITH (
FORMATFILE = 'c:\tmp\bcp.fmt'
)

bcp.fmt
3935 - size of image, you have to change collation if it needs.

See attachment.

No comments:

Post a Comment