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

  • SEARCH
  • Home
  • 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 6930355
In Process

The Archive Base Latest Questions

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

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

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

SET @imgNumber = 1

WHILE @imgNumber<> 101

BEGIN

SET @imgName = 'SELECT (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'

SET @imgNumber = @imgNumber + 1

END

GO

I am having problems with the @imgName. I can’t figure out how to get the value from the select statement not the (items) like below:

C:\Documents and Settings\Administrator\Desktop\photos\SELECT (items) FROM dbo.building_piclink

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-27T11:26:12+00:00Added an answer on May 27, 2026 at 11:26 am

    Your code has several problems:

    1) You’re selecting a file name from the view – but what if that view contains more than one entry?? Which filename are you selecting?? Your current code first of all doesn’t work at all the way it is, and even if it were working – you’re still potentially selecting hundreds of filenames into a single variable – which of course won’t work….

    So you’ll need to fix this here first:

    SET @imgName = 'SELECT (items) FROM dbo.building_piclink'
    

    First of all – loose the single quotes:

    SELECT @imgName = (items) FROM dbo.building_piclink
    

    But now – do you have a unique ID that you can select for? Or do you want to get just the first entry (whatever that is) ??

    So either you need:

    SELECT @imgName = ImageFileName FROM dbo.building_piclink WHERE .......... 
    

    and fill in that WHERE clause with a condition that guarantees to return just a single row, or use TOP 1:

    SELECT TOP (1) @imgName = ImageFileName  FROM dbo.building_piclink 
    

    In that case – you’ll just get exactly one filename – if you don’t specify an ORDER BY, then there’s no guarantee what you’ll get – maybe you’ll want to add a ORDER BY DueDate or something to prioritize which file names you get first.

    2) Your code for loading the image data is non workable, either – what you need to do is build up the SQL statement as a string, and then execute it (called dynamic SQL) – something like this:

    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'
    
    EXEC(@insertString)   -- actually execute your SQL statement!
    

    With these two fixes, you should be on the way to get this thing working

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

Sidebar

Related Questions

declare @a varchar(40) set @a='1.23e-4' declare @b decimal(27,12) if isnumeric(@a) =1 begin select @b=cast(@a
DECLARE @table table(XYZ VARCHAR(8) , id int) INSERT INTO @table SELECT '4000', 1 UNION
declare @servername varchar(2000) set @EmriServerit=(select @@servername) declare @dbname varchar(2000) set @dbname ='Test1' declare @Dir
declare @d varchar set @d = 'No filter' if (@d like 'No filter') BEGIN
declare @top int set @top = 5 select top @top * from tablename Is
declare @var sysname declare @sql varchar(5000) set @var = 'Table_name' set @sql = 'select
DECLARE @SQL VARCHAR(100) DECLARE @dbName VARCHAR(100)-- SET @dbName = 'somedbname'-- SET @sql = 'USE
DECLARE @TotalQuestions int; DECLARE @CorrectQuestions int; DECLARE @IncorrectQuestions int; SELECT ( SET CorrectQuestion =
declare @customerID int set @customerID=1 ;with cteDates as ( select dateadd(hh, datediff(hh, 0, getdate()),
DECLARE @EmployeeList varchar(100) SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') + CAST(Emp_UniqueID AS

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.