Sunday

howto put file into varbinary (OPENROWSET,BULK,SINGLE_BLOB) on MS SQLServer


CREATE TABLE [cmp].[tblCMPEmailAttachements](
[AttachmentID] [int] IDENTITY(1,1) NOT NULL,
[EmailID] [int] NOT NULL,
[FileName] [nvarchar](50) NULL,
[CreatedDate] [datetime] NULL,
[FileBody] [varbinary](max) NULL
) ON [PRIMARY]



Declare @attID int
Insert into cmp.tblCMPEmailAttachements (EmailID,FileName,CreatedDate) values (1,'1.gif',GETDATE())
SET @attID = SCOPE_IDENTITY();
update cmp.tblCMPEmailAttachements set
[FileBody] = (SELECT * FROM OPENROWSET(BULK 'C:\1.gif', SINGLE_BLOB)AS [FileBody] ) WHERE AttachmentID=@attID

more...

No comments:

test smtp server with powershell

Send-MailMessage -SMTPServer smtp.domain.com -To [email protected] -From [email protected] -Subject "This is a test email" -Body ...