Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6953399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:28:26+00:00 2026-05-27T14:28:26+00:00

I am using Microsoft Sql Server 2008. I am using a view ( dbo.building_piclink

  • 0

I am using Microsoft Sql Server 2008. I am using a view (dbo.building_piclink) to get photo names (@imgName) and insert the photos into a table from a file. I need to also take this photo name and add it into a column called att_name but I can’t figure out the syntax on the insert statement to add it in.

DECLARE @imgString varchar(800)
DECLARE @insertString varchar(3000)
DECLARE @imgNumber int
Declare @imgName varchar(100)

SET @imgNumber = 1

WHILE @imgNumber <> 10

BEGIN

SELECT @imgName = Lower(items) FROM dbo.building_piclink

SET @imgString = 'C:\Documents and Settings\Administrator\Desktop\photos\' + @imgName


SET @insertString = 'INSERT INTO dbo._building__ATTACH (DATA)
SELECT * FROM OPENROWSET(BULK N''' + @imgString + ''', SINGLE_BLOB) as tempImg'

Print @insertString

SET @imgNumber = @imgNumber + 1

EXEC(@insertString)   

END

GO

I have tried

SET @insertString = 'INSERT INTO dbo._building__ATTACH (DATA, ATTNAME)
SELECT * FROM OPENROWSET(BULK N''' + @imgString + ''', SINGLE_BLOB) as tempImg,' + @imgName

but I get an error like this:

Msg 208, Level 16, State 1, Line 1 Invalid object name
‘b26382_3_775682.jpg’

I have tried just doing the insert on the att_name:

SET @insertString = 'INSERT INTO dbo._buildingpoint__ATTACH (ATT_NAME)' + @imgName

with no luck. I am missing something in the syntax.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:28:27+00:00Added an answer on May 27, 2026 at 2:28 pm

    Well, yes, your insert string is not correct – right now, you get something like:

    INSERT INTO dbo._building__ATTACH (DATA, ATTNAME)
       SELECT * 
       FROM OPENROWSET(BULK N'b26382_3_775682.jpg', SINGLE_BLOB) as tempImg, b26382_3_775682.jpg
    

    while if you want to insert the file name as a string, you need to put it into single quotes (and I would also reverse the order of the column in the INSERT):

    INSERT INTO dbo._building__ATTACH (ATTNAME, DATA)
       SELECT 
          'b26382_3_775682.jpg', tempImg.* 
       FROM 
          OPENROWSET(BULK N'b26382_3_775682.jpg', SINGLE_BLOB) as tempImg 
    

    Also, as Jon of All Trades suggested : can you try to run just this INSERT statement in isolation, just to see if that statement on its own works correctly? Once that works – then integrate it into your stored proc and turn it into a dynamic SQL statement…

    Update: yes – as I said in my answer (a few lines up from here): you need to put the filename that you want to insert into attName into single quotes – your latest comments still doesn’t do that….

    Try this:

    SET @insertString = 
        'INSERT INTO dbo._building__ATTACH (ATTNAME, DATA) ' + 
        'SELECT ''' + @imgName + ''', tempImg.* ' + 
        'FROM OPENROWSET(BULK N''' + @imgString + ''', SINGLE_BLOB) as tempImg'
    

    Does this work?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Microsoft SQL Server 2008 Management Studio to create a relational schema by
I am using Microsoft Sql Server 2008. with this below query certain rows are
I have a website using Microsoft SQL 2008 server over local network. Sometimes, SQL
I am using Microsoft SQL Server 2008. While generating custom reports, I need to
i'm running into a strange problem in Microsoft SQL Server 2008. I have a
Using Microsoft SQL Server 2008, let's say there is a table1 that keeps the
I'm using Microsoft SQL Server 2008. I'm not an expert with it but I
I am developing one web application using asp.net 2005 and Microsoft SQL Server 2008
Is there a way to synchronize two SQL Server 2008 databases(any edition) using Microsoft
Hello I am working on a SQL database Using Microsoft SQL server 2008 R2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.