Quotes Around The Comma Delimited String

Oct 18, 2005

I am trying to build a dynamic where  statement for my sql stored prcoedure

  if len(@Office) > 0   select @strWhereClause = N'cvEh.chOfficeId in (select id from dbo.csfParseDeLimitedText( ' + @vchOffice  +  ',' + ''',''' + '))' + ' and ' + @strWhereClause

In this case users can enter comma delimited string in their search criteria. So if they enter we1, we2, we3 then my sql statement should look like

select @strWhereClause = cvEh.chOfficeId in (select id from dbo.csfParseDeLimitedText('we1', 'we2', 'we3'),',')

My csfParseDeLimitedText function looks like this

Create  FUNCTION [dbo].[csfParseDeLimitedText] (@p_text varchar(4000), @p_Delimeter char(1))RETURNS @results TABLE (id varchar(100))ASBEGIN declare @i1 varchar(200)declare @i2 varchar(200)declare @tempResults Table (id varchar(100))while len(@p_text) > 0 and charindex(@p_Delimeter, @p_text) <> 0beginselect @i1 = left(@p_text, charindex(@p_Delimeter, @p_text) - 1)insert @tempResults select @i1select @p_text = right(@p_text, len(@p_text) - charindex(@p_Delimeter,@p_text))endinsert @tempResults select @p_text

insert @resultsselect *from @tempResultsreturnEND

 

My problem is it does not put quotes around the comma delimited stringso I want to put 'we1' , 'we2'. These single quotes are not coming in the dynamic sql statement. How can I modify my query so that single quotes around each entry should show up.

Any help will be greatky appreciated.

Thanks

View 1 Replies


ADVERTISEMENT

Flat File Comma Delimited Ignoring Quotes

Dec 27, 2007



hi im using the import export wizard to import a file where my recoreds are comma delimited but when i HAVE to use a comma im using quotes to escape

"CN=Administrator,CN=Users,DC=aboneng,DC=local",user,Administrator,Built-in account for administering the computer/domain,"CN=Administrator,CN=Users,DC=aboneng,DC=local",4,20050421014154.0Z,20060518065932.0Z,

with this example

CN=Administrator,CN=Users,DC=aboneng,DC=local === should be the first column
user, ==== the second column
Administrator === third and so forth.

i thought it was a standard to use quotes when escaping your delimiter but sql is bringing in the records as comma delimited as normal is there anyway around this?

View 1 Replies View Related

SQL Server 2008 :: Search Each And Every String In Comma Delimited String Input (AND Condition)

Mar 10, 2015

I have a scenario where in I need to use a comma delimited string as input. And search the tables with each and every string in the comma delimited string.

Example:
DECLARE @StrInput NVARCHAR(2000) = '.NET,Java, Python'

SELECT * FROM TABLE WHERE titleName = '.NET' AND titleName='java' AND titleName = 'Python'

As shown in the example above I need to take the comma delimited string as input and search each individual string like in the select statement.

View 3 Replies View Related

SELECT WHERE IN Comma Delimited String

Jun 3, 2008

Hello

I have a table with column Options where each field contains a comma delimited list of ID numbers.

I want to select any records where a certain ID number appears in that list.

So something like:

SELECT * FROM Table t1
WHERE MyID IN (SELECT Options FROM Table t2 WHERE t1.ID = t2.ID)

But that gives me the error:

Syntax error converting the varchar value '39,20' to a column of data type int.

I feel I'm close though! Could anyone point me in the right direction?

Many thanks

Square

View 3 Replies View Related

Insert A Comma Delimited String

Nov 22, 2013

I have a problem in a stored procedure trying to insert a comma delimited list into rows.The parameters for example would be somthing like....

@GarageID int = 20,
@Cars nVarChar(200) = Ford~Fiesta,BMW~320,Volvo~340,Jaguar~XJS

I need to split where the comma is for each new row, and separate each value from either side of the '~' like so....

GarageID Make Model
--------------------------------
20 Ford Fiesta
20 BMW 320
20 Volvo 340
20 Jaguar XJS

View 2 Replies View Related

Splitting A Comma Delimited String

Oct 1, 2007

I have a string like say: '3:4:5:4,2:4:1,4:1:2:5:2'. Now I need to split the substrings delimited by commas. So my final output shall be

3:4:5:4
2:4:1
4:1:2:5:2


I did write a piece of code to achieve the same, but I feel its not so efficient. Can anyone suggest me a better way, if any? My code is as follows:

Declare @person as varchar(255), @cnt smallint,@loc smallint,@prevloc smallint, @str varchar(255)
Select @prevloc=0,@loc=1,@cnt=1,@person = '3:4:5:4,2:4:1,4:1:2:5:2'
While @loc != 0
begin
set @prevloc=(case when @loc = 1 then 0 else @loc end) +1
set @loc = charindex(',',@person,@loc+1)
Set @str = substring(@person,@prevloc,(Case when @loc = 0 then len(@person) - @prevloc + 1 else @loc - @prevloc end))
print 'String = ' + @Str
set @cnt=@cnt+1
end

RESULT
------
String = 3:4:5:4
String = 2:4:1
String = 4:1:2:5:2


Note: My actual purpose is to also sub split it again with ':' delimiter too. So looking for an efficient code.

View 4 Replies View Related

Stored Procedure And Comma Delimited String

Dec 8, 2006

I'm passing a comma delimited string to my SP, e.g.:"3,8,10,16,23,24"I need to retreive each number in this string and for every number found I need to execute some sode, say add "AND SportID="+numberfoundHow can I do that?

View 6 Replies View Related

Multiple Rows Into A Comma Delimited String

May 22, 2007

I have the following table:id name1 yes2 no3 what4 is5 this6 niceThe amount of rows can vary from 1 to 50. I only need the name column.What SQL statement do I have to execute to get the following:yes,no,what,is,this,nice,  (trailing , is acceptable)Thanks!

View 1 Replies View Related

How To Parse A String Column With Comma Delimited

Jul 20, 2005

Hi,I would like to parse out each value that is seperatedby a comma in a field and use that value to join to another table.What would be the easiest way to do so without having towrite a function or routine ?EX.Table AAACOL1 COL21 11, 124, 1562 11, 505, 600, 700, ...Table BBBCOL1 COL211 Desc11124 Desc124156 Desc 156

View 2 Replies View Related

Transact SQL :: How To Split Comma Delimited String

Oct 8, 2008

I have a parameter called Id in my SP which will be of nvarchar data type and i'm going to get the multiple ids at a time seperated by commas in that parameter from the application. Now my requirement is to update a table with these comma seperated ids in seperate rows.

For example, if i have 2 parameters called Id1 and Id2. Id1 will contain only one value and will be of int data type and Id2 will be of nvarchar data type as i can get multiple ids delimited by a comma from the application.

Suppose Id1 = 1 and Id2 = '1,2,3,4'. Then I have to update id2 in the tables seperately like wherever Id1 is '1' i need to update Id2 column for 4 rows with the value 1, 2, 3, 4 respectively in different rows.
 
how can i do this in T-SQL? How can i split the data of parameter Id2 in 4 different rows?

View 24 Replies View Related

How Do I Split And Insert A Comma Delimited String To A Table?

Oct 13, 2004

I am passing in a string of dates, delimited by a comma.

So

01/01/04, 02/01/04, 03/01/04

etc

I would like to enter each of these values into a table via an INSERT stored procedure.

Does anyone have any code for this?

View 1 Replies View Related

Conditional Where Clause With Comma Delimited String And Link Table

Jul 24, 2007

 I have 3 tables:tblUsersuserID int PK(...)tblSportsSportID int PK(...)tblUsersAndSports  (contains the link between users and sports..a single user may have multiple entries in this table)Usercode intSportID intNow I want a stored proc that enables visitors to search on all user that have a specific sportID.The SportIDs to search on are in the var @sports as a comma delimited string,like '3,6,7'@sports may also be null (or an empty string if that is more convenient for building the SQL) when a visitor does not want to search on any of the sports a user practices, in that case no selection based on the sport criteria should be done, so ONLY filter on sports when the value of @sports is not nullpseudo code:select * from tblUserswhere   if @sports not null    user.sports in @sportsand username=@usernameand age=@agehelp is greatly appreciated!

View 10 Replies View Related

Passing A Comma Delimited String Of Parameters To A Stored Proc

Jul 30, 2007

Hello,
I have a number of multi-select parameters which I would like to send to a stored procedure within the dataset for use in the stored procedure's IN() statement which in turn is used to filter on or out particular rowsets.

I considered using a hidden string parameter set = " ' " + join(parameter.value, ',') + " ' " so that the hidden parameter would then contain a comma delimiated string of the values selected, which would then be sent on to the stored proc and used in the WHERE clause of one of the queries internal to the stored proc.
But before I start dedicating time to do this I wanted to inquire if anyone here with far more expertise could think of a faster or less system heavy method of creating a single string of comma delimited parameter selections?

Thanks.

View 3 Replies View Related

Comma Delimited File With Comma Inside A Column

Nov 9, 2007

Using Flat File Connection Manager, I am specifying Text Qualifier = Double quotes{"}, and i have TXT file with one column for lastname and first name as "LN,FN", and settings are set to comma delimted, now the connectin manager is creating two different columns for LN and FN,

it was never a problem in DTS 2000.

any work around.

Thanks,

View 7 Replies View Related

SELECT WHERE (any Value In Comma Delimited List) IN (comma Delimited List)

Jul 2, 2005

I want to allow visitors to filter a list of events to show only those belonging to categories selected from a checklist.

Here is an approach I am trying:

TABLE Events(EventID int, Categories varchar(200))

EventID Catetories
--------------------------
1           ‘6,8,9’
2           ‘2,3’

PROCEDURE ListFilteredEvents
   @FilterList varchar(200)    -- contains ‘3,5’
AS
SELECT EventID FROM Events
WHERE (any value in Categories) IN @FilterList

Result:

EventID
----------
2

How can I select all records where any value in the Categories column
matches a value in @FilterList. In this example, record 2 would be
selected since it belongs to category 3, which is also in @FilterList.

I’ve looked at the table of numbers approach, which works when
selecting records where a column value is in the parameter list, but I
can’t see how to make this work when the column itself also contains a
comma delimited list.

Can someone suggest an approach?

Any examples would be greatly appreciated!
Gary

View 3 Replies View Related

Comma Delimited Row

Jun 23, 2006

Hi,

Good evening! I have a problem. I have a namelist coming from a distribution list of an active directory. When I converted it to csv file, the members reside in just one column and separated by a comma. I want the names to be separated in a row one by one. I tried it on excel and I used the transpose column but to no avail. My last resort is to import it on sql but the names on the column was cut and not complete. Do you have any idea how to do this. Your help is highly appreciated.

this is the sample file..

names
kelly.yap, lizzy.fox, yahoo, finance.dep, hope.miller, porly.john

the maximum names in a row is 566.

thanks in advance.
myBU

View 2 Replies View Related

Comma Delimited Results Help Please

Aug 11, 2004

Would like to have a view created to display the result at the bottom of this message. We will be using Dreamweaver to display the information from this view. Also, for the record, we are using sql 2000. Any help would be greatly appreciated.

tblservers
servid servername
1 server1
2 server2
3 server3

tblapplications
appid appname
1 app1
2 app2
3 app3

tblapplink
id appid servid
1 1 1
2 1 2
3 1 3
4 2 1
5 2 3
6 3 1

we want to display this information as below:

appname serverlist
app1 server1, server2, server3
app2 server1, server3
app3 server1

Thank you very much,
mrtwo

View 2 Replies View Related

Comma Delimited Processing

Dec 28, 2006

Suppose I have a table named Test (referred in the query below)

Category Indicators
ctgy1Y,,,,
ctgy2Y,Y,Y,N,
ctgy3,Y,,Y,

and If I would like to transform this table to

Category Indicators
ctgy1Y
ctgy2Y
ctgy2Y
ctgy2Y
ctgy3Y
ctgy3Y

I am able to do it using the logic below

CREATE TABLE dbo.Numbers (Number INT IDENTITY(1,1) PRIMARY KEY CLUSTERED)
WHILE COALESCE(SCOPE_IDENTITY(), 0) < 5
BEGIN
INSERT dbo.Numbers DEFAULT VALUES
END

SELECT category,
SUBSTRING( Value, Number, CHARINDEX( ',', Value + ',', Number ) - Number ) as program
FROM Test
inner
JOIN Numbers
ON SUBSTRING( ',' + Value, Number, 1 ) = ','
and CHARINDEX( ',', Value+',', Number ) - Number <> 0
where Number <= Len(Value) + 1

But I would like to Transform this table into something like the one below (where if 'Y' before 1st comma then Q1, if 'Y' Before 2nd comma then Q2 and so on

Category Indicators
ctgy1Q1
ctgy2Q1
ctgy2Q2
ctgy2Q3
ctgy3Q2
ctgy3Q4

What is the best and efficient way to obtain this? Any help will be greatly helpful.


Thanks
Ram

View 4 Replies View Related

Comma Delimited Errors

Apr 2, 2007

I need to import comma delimited text files into sql tables. in one of the column, there is a comma in the string itself. e.g.



Cust_ID Name Phone Address1 Address2





Date that I have:

001,juia, anderson,4694568855,,Cedar Spring



The data does not have double quote as text qualifiers. but as you see, on the Name column, there is a comma, which is not a delimiter. can anybody give any suggestions on how i can deal with that? i would appreciate it so much.



thanks

View 2 Replies View Related

Comma Delimited List Of Views

Aug 13, 2007

Is it possible to get a comma delimited list of the views in a DB?

View 7 Replies View Related

How Can I Get A Comma Delimited List Of The Views In My Db

Mar 18, 2008

How can I get a comma delimited list of the views in my db?
("view1","view2","view3",etc...)

View 3 Replies View Related

Help - How To Select From A Comma Delimited Field ?

Nov 2, 2003

Dear SQL,

Lets say I have a field: User_Names

and it can have more than one name
example: "Yovav,John,Shon"

How can I select all the records that has "Yovav" in them ?

I try some like this:
SELECT * FROM User_Table WHERE User_Names IN ('Yovav')

but it only works if the field User_Names only has "Yovav" in it with no extras...


is there some SQL function to tell if string is found in a field ?

Any hope 4 me ?

View 2 Replies View Related

Comma Delimited Text File

May 18, 2004

Hi I'm pretty new to using Microsoft Visual C# .NET and I want to upload a comma delimited text file from my local machine into a table in an sql server database through a web app. How would I go about programming this and what controls do I need? Any help would be much appreciated. Thanks in advance.

View 4 Replies View Related

Passing Comma Delimited Parameter To SP

Apr 14, 2005

Is this possible? I find it hard to believe that this could be sooo difficult. I have a simple select stored procedure that has one parameter. My application is passing a comma delimited string of values to be used in the IN clause.
Ex: Where x In(@parametername)
the x column is an integer. How can one work around this???
Thanks!

View 4 Replies View Related

Creating A Comma Delimited List

Jul 11, 2005

Hi,

I have a complex query where each row in the final dataset is a
product.
However each product has a number of authors associated with it. 
What I
would like to do is have a query/subroutine join the authors to the
product,
as a string:


ProductID  
Title                       
Authors
1           The Sacred and the Profane   John Rieggle, George
Alexi
2           Dancing
in the Dark          Dan
Brown, Peter Kay, Paul
Dwebinski

Products
Table
==============
ProductID
Title

Authors
Table
=============
AuthorID
Name

Product Authors
Table
=====================
AuthorID
ProductID

Is this at all
possible?

Thanks

jr.

View 3 Replies View Related

Split Up Comma-delimited Field

Jun 7, 2002

I have a row in a SQL table that has 4 numerical values, separated by comma. I'd like to take this and make it 4 separate columns. Values are not always the same length, but are always delimited by commas.

Any ideas how I could do this in T-SQL?

View 9 Replies View Related

Inner Join On A Comma Delimited List?

Jul 12, 2006

Hi,

I have the following query:


SELECT *
FROM News INNER JOIN
Newsletters ON News.ID = Newsletters.fkNewsID


My problem is that fkNewsID can contain a comma delimited list of various IDs. Is there a way to properly do the join in this case?

View 1 Replies View Related

Help Moving Comma Delimited Data

Jan 21, 2004

I posted this originally in the incorrect forum I believe so I am reposting this in here which I believe is the proper place.

I need to move essentially a flat file from one server to another one and export it into a database on the second server. Does anyone have an easy process to accomplish this? I am currently at a loss. Any advice would be much appreciated.

Thanks

View 14 Replies View Related

Export To Comma Delimited File

Aug 4, 2007

I'm trying to upload a small Web application with a one table database. The hosting company, GoDaddy requires that I upload the database as a comma delimited file.
I created the database in Visual Web Developer Express but also have Visual Studio and SQL Server Management Studio Express.
I can't figure out how to export the database into a comma delimited file using any of these tools.
This should be simple like it is in Access but that doesn't seem to be the case. This is holding up deploying my Web Application.

Can anyone help me?

Thanks

View 1 Replies View Related

Creating Columns From A Comma Delimited Row

Aug 20, 2007

Hi All

This is my first official post...very exciting:)

OK....

I need to split a string, based on comma delimetrs, into columns of a table.

I am using SQL Server 2005.
The plan is to use webmethods (Integration Software) to receive a flat file, loop through the records in that flat file and during each iteration of the loop call a SQL stored procedure that will split the record, based on comma delimetrs, into columns of a table.

A typical record will look like this:
AP05-07,ACTUAL,ZA01,......

I have looked at some of the past solutions to this type of post, but am battling to understand....

So if its possible, is there a simple way to create a stored procedure that will do this?

Many thanks

View 4 Replies View Related

COMMA Delimited TEXT FILE

Jul 20, 2005

Hi,On SQLServer 2000, I have a table with a following structure:MYTABLEcol1 char,col2 date,col3 numberMy Objective:------------Externally (from a command line), to select all columns and write theoutput into a file delimited by a comma.My method:---------1. Probably will use OSQL or BCP to do this.2. Use the following syntax:select RTRIM(col1) +','+ RTRIM(col2) +','+ RTRIM(col3)from MYTABLE;My 3 Problems:-------------1) If there is a NULL column, the result of concatenating any value withNULL, is NULL. How can I work around this? I still want to record thiscolumn as null. Something like say from the example above, if col2 isnull, would result to: APPLE,,52) The time format when querying the database is: 2003-06-24 15:10:20.However, on the file, the data becomes: 24 JUN 2003 3:10PM. How can Ipreserve the YYYY-MM-DD HH:MM:SS format? Notice that I also lost theSS.3) Which utility is better? BCP or OSQL?For OSQL, it has a "-s" flag which gives me the option of putting acolumn separator. But the result is:"APPLE ,14 JUN 2003 , 5"I don't need the extra space.While for BCP, there is no column separator flag.You will notice from my inquiry above that my background in SQLServer isnot very good.Thanks in Advance!!RegardsRicky*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 1 Replies View Related

How To Handle Comma Delimited Columns

Oct 27, 2007

Hello

I have this newbie question regarding SSIS:

I have a table named People(#Code, Name, eMailList), where the column eMailList has a list of email addresses separated by commas, like "someone@hotmail.com,someone@gmail.com,someone@yahoo.com".

I would like that for each Person, extract the email address info in such a way that I can insert into the following table: EMail(#Code, #ID, Address), where Address has a single email address.

How can I accomplish that?

Thanks a lot.

View 5 Replies View Related

Splitting A Comma Delimited Column

Feb 12, 2008



Hi

I wondered if anyone could help me. I have a table that holds an ID in the first column then a list of values split by commas in the 2nd column i.e.:

IDColumn: 1
2ndCoumn: 1stvalue, 2ndvalue, 3rdvalue, 4thvalue

I am trying to return as a dataset of this that shows the ID as column 1 then each value in the 2nd column as individual columns if I use SELECT LEFT('2ndColumn,PATINDEX(',',2ndColum)-1) I can return the first value as a column but then can't return any further values individually after the first column, I am just learning the new functionality in SSIS so not sure whether this would be my answer as apposed to T-SQL, if anyone has any advice on this it would be greatly appreciated?

Thanks in advance

Caralyn

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved