SQL Server database project issue using BulkColumn in view

Raj D 616 Reputation points
2022-12-15T01:52:48.05+00:00

I'm using SQL Server database project to deploy objects to Azure SQL database. I have a view using common table expression with the below code. This object is part of build and run into the following error SQL71005: The reference to the column "BulkColumn" could not be resolved.

SQL

WITH cte   
AS   
(  
SELECT BulkColumn  
  FROM OPENROWSET(  
  BULK 'azurestorage/blobpath.json',  
  DATA_SOURCE = 'azureblobcontainer',  
  SINGLE_CLOB) AS bc  
)  

Could you please help me with a solution by not changing the Build Action -> None

Thank you

Azure SQL Database
SQL Server Other
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-12-15T22:49:49.197+00:00

    A workaround is to embed the query in dynamic SQL

       SELECT @sql = '     WITH cte   
            AS   
            (  
            SELECT BulkColumn  
              FROM OPENROWSET(  
              BULK ''azurestorage/blobpath.json'',  
              DATA_SOURCE = ''azureblobcontainer'',  
              SINGLE_CLOB) AS bc  
            )  
    

    And, yes, it's ugly. It would certainly be better if SSDT could get its act together.

    You can report bugs here: https://feedback.azure.com/d365community/forum/04fe6ee0-3b25-ec11-b6e6-000d3a4f0da0.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. YufeiShao-msft 7,146 Reputation points
    2022-12-15T07:53:48.077+00:00

    Hi @Raj D

    Essentially it is telling you that there is a reference to some object in your procedure that is invalid, it might just be a plain and simple broken procedure and have not got all the objects yet. you may need to check if your stored procedure is valid

    https://techcommunity.microsoft.com/t5/sql-server-blog/importing-json-files-into-sql-server-using-openrowset-bulk/ba-p/384480

    -------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2022-12-16T08:02:10.9+00:00

    An MVP colleague suggested a better workaround, define the column alias explicitly:

       WITH cte   
            AS   
            (  
            SELECT BulkColumn  
              FROM OPENROWSET(  
              BULK 'azurestorage/blobpath.json',  
              DATA_SOURCE = 'azureblobcontainer',  
              SINGLE_CLOB) AS bc(BulkColumn)  
            )  
    

    He did not have the possibility to test it, but I would be quite disappointed if it does not work.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.