We help IT Professionals succeed at work.
Get Started

Issue with a stored procedure.

TECH_NET
TECH_NET asked
on
201 Views
Last Modified: 2010-04-21
I have a stored procedure as follows:

CREATE ROCEDURE [dbo].[Keywords_RetrieveDetails]
(
      @ID int,
      @TABLE_NAME varchar(500)='KEYWORD_LIST'
)
AS SET NOCOUNT OFF;  
declare @sql nvarchar(4000)

SET @sql='SELECT KEYWORD_ID, ISNULL(NAME,'') AS NAME,ISNULL(DESCRIPTION,'') AS DESCRIPTION, ISNULL(SORT_ORDER,0) AS  SORT_ORDER, ISNULL(KEYWORD_CATEGORY_ID,-1) AS KEYWORD_CATEGORY_ID, ISNULL(PARENT_KEYWORD_ID,-1) AS  PARENT_KEYWORD_ID, ISNULL(DISPLAY_STATUS_ID,1) AS DISPLAY_STATUS_ID, ISNULL(ROLE_ID,-1) AS ROLE_ID
  FROM ' +  @TABLE_NAME + ' WHERE KEYWORD_ID = ''' +CAST(@ID AS VARCHAR) + ''''
exec sp_executesql @sql


When i execute the same, i see the results but the 2nd column ( ie NAME ) is not displayed in the resultant record. But when i execute the following SQL statement it does work.
SELECT
      KEYWORD_ID,
      ISNULL(NAME,'') AS NAMES,
      ISNULL(DESCRIPTION,'') AS DESCRIPTION,
      ISNULL(SORT_ORDER,0) AS  SORT_ORDER,
      ISNULL(KEYWORD_CATEGORY_ID,-1) AS KEYWORD_CATEGORY_ID,
      ISNULL(PARENT_KEYWORD_ID,-1) AS  PARENT_KEYWORD_ID,
      ISNULL(DISPLAY_STATUS_ID,1) AS DISPLAY_STATUS_ID,
      ISNULL(ROLE_ID,-1) AS ROLE_ID
  FROM
      KEYWORD_DISPLAY_STATUS
  WHERE
      KEYWORD_ID = 1
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE