Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
tmcrouse
Starting Member
12 Posts |
Posted - 2014-12-02 : 10:53:34
|
I am having a problem finding the correct code to insert my .pdf file into my SQL table. The table name is Prog with the following columns:Prog_ID(PK) Prog_NM Prog_Desc Attachment(varbinary(max))10 Smoking Quit Smoking100 HCL Healthy Living .pdf1001 Diabetes Diabetes Fotonovellas10.0 BCS Breast CancerPharm1 ACE/ARB ACE/ARB ComplianceAs of now, the .pdf I have is for the Prog_ID 100, HCL. I need to put the .pdf attachment on this row.I have found all sorts of various code such as: INSERT INTO Prog (pdfData) SELECT * FROM OPENROWSET(BULK 'c:\pdfSample.pdf', SINGLE_BLOB); Where the select is, would I follow after openrowset where Prog_ID = '100'And then include the rest of the statement with the path? Placing this .pdf in the database, it seems that it would actually point to the c:\ drive and not actually upload the attachment into the database. If that is the case, I would have to put the .pdf on our SharePoint and point to that path. The .pdfs will not be very large and I was thinking it would be better to have them actually stored in the database. any help would be greatly appreciated.tmc |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-02 : 11:13:43
|
BULK INSERT will insert the data, not the file path. See examples here: http://msdn.microsoft.com/en-CA/library/ms191184.aspx"Where the select is, would I follow after openrowset where Prog_ID = '100'"doesn't make sense. You are inserting a new row into Prog, which means you also need to supply a value for Prog_Id. OTOH the SELECT statement queries an OpenRowset and there is no column Prog_Id to look at. |
|
|
tmcrouse
Starting Member
12 Posts |
Posted - 2014-12-02 : 11:19:25
|
Oh, I have all the rows that will be in this table already. I am just adding the .pdf attachment to an already existing row. I will see if I can find an alternative query. Maybe it should be update instead of insert. I will view the examples from the link. Is there a way after I have my questions answered successfully to mark as solved?tmc |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-02 : 11:27:20
|
then you will do an UPDATE, not an INSERT |
|
|
tmcrouse
Starting Member
12 Posts |
Posted - 2014-12-02 : 14:41:49
|
UPDATE prog SET (bulk attachment='c:\users\ad36742\documents\qualproject\miscfiles\2013 commercial healthy checklist mailer 1.pdf', single_blob)WHERE prog_id = '100';So like the above? Just asking because it did not work.tmc |
|
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-12-02 : 15:04:39
|
Does that look like valid syntax (it's not) try this (untested, but hope you get the idea):UPDATE prog SET Prog_Desc Attachment=(SELECT * FROM OPENROWSET(BULK 'c:\pdfSample.pdf', SINGLE_BLOB))WHERE prog_id = '100'; |
|
|
|
|
|
|
|