Click here to Skip to main content
15,559,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've following table
CREATE TABLE [dbo].[Customer](
    [CustomerID] [int] IDENTITY(1,1) NOT NULL,
    [City] [varchar](50) NULL,
    [Country] [varchar](50) NULL,
    [PostalCode] [nchar](10) NULL,
    [Picture] [varbinary](max) 

please help me to write query to insert data in this table

Thanks in advance
Updated 21-Oct-13 2:28am

Share this answer
Like this
CREATE TABLE [dob].[Customer](
    [CustomerID] [int] IDENTITY(1,1) NOT NULL,
    [City] [varchar](50) NULL,
    [Country] [varchar](50) NULL,
    [PostalCode] [nchar](10) NULL,
    [Picture] [nvarchar]()  
) ON [PRIMARY]				

INSERT INTO  [dbo].[Customer] --([City], [Country], [PostalCode], [Picture])

SELECT [CustomerID]
  FROM [dbo].[Customer]

CustomerID	City	        Country	    PostalCode	Picture
1	        Oshkosh	        USA	    54903     	0x4F
2	        Harlingen	USA	    78551     	0xCE

DECLARE @strImage nvarchar(888)
SET @strImage = 'c:\users\PT\MyImage.jpg'

DECLARE @strExec [nvarchar](999)
SET @strExec = N'INSERT INTO [dbo].[Customer](Picture) SELECT * FROM OPENROWSET(BULK N''' + @strImage + ''', SINGLE_BLOB) as [imageDedicated]'


[end edit]
Share this answer
prashantttt 22-Oct-13 1:06am    
in INSERT query what is it 0xCE ???
RedDk 22-Oct-13 1:45am    
It's just a hexadecimal sequence. See the BOL ... lookup binary data type. Best idea is to go to and download and install AdventureWorks database sample (in any or all of the forms found). Many references in BOL point to the tables in these packages.
prashantttt 22-Oct-13 2:27am    
but how can i get to know what to write for which file...?
the way u have written 0x4F for first image, 0xCE for second image
RedDk 23-Oct-13 0:06am    
see edit
RedDk 22-Oct-13 12:01pm    
See my revision @ [edit]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900