Solved

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

Posted on 2011-09-04
4
288 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
export sql results to csv 6 41
Filtering characters in an SQL field 2 16
SQL Server group with two values 4 35
Need return values from a stored procedure 8 21
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 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