Solved

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

Posted on 2011-09-04
4
281 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
  • 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 500 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query 8 50
How to write a sql query returning a result  with my date time template? 8 41
SQL query with cast 38 43
TSQL - How to declare table name 26 30
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

773 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