Why Dynamic Sql written in procedure working and returning data on development server but not returning on production server

BIDYUT KARMAKAR 20 Reputation points
2024-02-08T16:39:24.89+00:00

Why Dynamic Sql written in procedure working and returning data on development server but not returning on production server

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,917 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
100 questions
{count} votes

2 answers

Sort by: Most helpful
  1. way0utwest 81 Reputation points MVP
    2024-02-08T17:31:52.66+00:00

    Dynamic SQL is often data driven, either the data used to create the query or the data being queried. What is often helpful is something like this in both dev and prod: DECLARE @sql VARCHAR(MAX), @id int SELECT @sql = 'select * from mytable where id = ' + CAST(@id AS VARCHAR(10)) SELECT @sql -- exec(@sql) Instead of executing the code, print it and make sure it is well formed, and run it separately.

    0 comments No comments

  2. Erland Sommarskog 112.2K Reputation points MVP
    2024-02-08T21:54:42.54+00:00

    It's not working on the production server, because your code is making some assumption that is not true on the production server.

    What assumption? Well, since you did not provide any details, we cannot say more.

    0 comments No comments

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.