Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to trim first and last character of a parameter in sql

Posted on 2011-09-04
4
Medium Priority
?
301 Views
Last Modified: 2012-05-12
i have the following sql

Declare @QuizID varchar(500)
set @QuizID='2,3,4,5,6'
butI need something like this
Select * tblQuiz where QuizID in (2,3,4,5,6)
how can i trim the apostrophe characcter in variable @QuizID
0
Comment
Question by:mmalik15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:mmalik15
ID: 36480174
this does not work
Select * tblQuiz where QuizID in ('2,3,4,5,6')
but this does work
Select * tblQuiz where QuizID in (2,3,4,5,6)
0
 
LVL 6

Expert Comment

by:c1nmo
ID: 36480260
 Declare @QuizID varchar(500)
set @QuizID=('2,3,4,5,6')


SELECT TOP 1000 [id]
      ,[mynum]
  FROM [dbPerm].[dbo].[ee_in_num_list] where  
   CHARINDEX( ',' + convert(varchar,mynum) + ',', ',' + @QuizID + ',' ) > 0
0
 
LVL 6

Expert Comment

by:yjchong514
ID: 36480265
Dear EE members,

Please refer the following site:
http://www.source-code.biz/snippets/mssql/1.htm

Good Luck!

Regards,

yjchong514
0
 
LVL 6

Accepted Solution

by:
c1nmo earned 2000 total points
ID: 36480285
Updated to use your table and column names:-

Declare @QuizID varchar(500)
set @QuizID=('2,3,4,5,6')

SELECT *
  FROM tblQuiz  where  
   CHARINDEX( ',' + convert(varchar,QuizID) + ',', ',' + @QuizID + ',' ) > 0
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question