is there a describe or show function in SQL server 2022?

Jonathan Brotto 420 Reputation points
2024-08-08T13:47:29.87+00:00

I have a query in the SQL 2005 server we use for archive retrieval and a similar query in our 2019 box works with no issue.

Declare @POnumber varchar(max) = '6801415970'

SELECT * FROM dbo.SA15 WHERE PONO =  /*'6801415970'*/ @POnumber


SELECT * FROM dbo.SA15B WHERE PONO = /*'6801415970'*/ @POnumber

SELECT TOP 100 * FROM SA15

Msg 139, Level 15, State 1, Line 0

Cannot assign a default value to a local variable.

Msg 137, Level 15, State 2, Line 3

Must declare the scalar variable "@POnumber".

Msg 137, Level 15, State 2, Line 6

Must declare the scalar variable "@POnumber".

SQL Server Training
SQL Server Training
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Training: Instruction to develop new skills.
15 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 112.7K Reputation points MVP
    2024-08-08T21:39:41.92+00:00

    Yes, the syntax with assigning value to variables in the DECLARE statement was introduced in SQL 2008 and was not available in SQL 2005. You need to do:

    DECLARE @POnumber varchar(MAX)
    SELECT @PONumber = '6801415970'
    SELECT * FROM dbo.SA15r WHERE PONO = @PONumber
    

0 additional answers

Sort by: Most helpful

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.