Split Function - Sql Server 2005

May 22, 2008

In my table, column1 having a comma separated values.I want to display in rowwise.

for example:

column1

aa,ss,ff

 

output should be

aa

ss

ff

 

Pls. help me..I want to do thr query.

View 22 Replies


ADVERTISEMENT

SQL Server 2012 :: Call A Split Parameter Function

Sep 15, 2014

In t-sql 2012, the followinng sql works fine when I declare @reportID.

IF @reportID <> 0
BEGIN
SELECT 'Students report 1' AS selectRptName, 1 AS rptNumValue
UNION
SELECT 'Students report 2', 2
UNION

[code]...

However when I use the sql above in an ssrs 2012 report, the query does not work since the @reportID parameter can have 0, 1, or up to 200 values.Thus I am thinking of calling the following following function to split out the parameter values:

FUNCTION [dbo].[fn_splitString]
(
@listString VARCHAR(MAX)
)
RETURNS TABLE WITH SCHEMABINDING
AS
RETURN
(
SELECT SUBSTRING(l.listString, sn.Num + 1, CHARINDEX(',', l.listString, sn.Num + 1) - sn.Num - 1) _id
FROM (SELECT ',' + LTRIM(RTRIM(@listString)) + ',' AS listString) l
CROSS JOIN dbo.sequenceNumbers sn
WHERE sn.Num < LEN(l.listString)
AND SUBSTRING(l.listString, sn.Num, 1) = ','
)

GO

how to remove the @reportID <> 0 t-sql above and replace by calling the fn_splitString function?

View 2 Replies View Related

Split Function

Apr 7, 2008

Hi

I have tried like this. but I cant execute my SP it ended up with errors.

IF (@FirstLetters IS NOT NULL)
BEGIN
SET @FirstLetter = 'SELECT SplitValue FROM dbo.FnSplitString('+@FirstLetters+','',''))'
print @FirstLetter
END

SELECT
P.PUB_ID AS ''PubId'',
P.PUB_TITLE AS ''PubTitle''

FROM HDS_PUBLICATION P
INNER JOIN HN_IM_JOIN IM
ON IM.PUB_UNID = P.PUB_UNID,
HDS_CUSTOM C,
WD_PUBLIC_SHELF S,
HDS_TOPIC T
WHERE P.PUB_UNID = C.PUB_UNID AND C.CUSTOM3 = ''False''
AND P.PUB_ID = S.PUB_ID
AND P.PUB_UNID = T.PUB_UNID
AND S.Audience = ''Public''
' + @FilterByLang + '
ANDP.PUB_TITLE LIKE '+ @FirstLetter +'''%''' +'

EXEC SP

Any one please clear me

Thanks,
shakthiA

View 3 Replies View Related

Split Function

Aug 21, 2006



Is there any split function in sql server 2005. I just want to pass a string to a stored procedure. it should split that string when it encounters a space. for ex, consider the string " the intel mother board" it should give "the,intel,mother,board" as result.



View 6 Replies View Related

Split Function In A Transaction

Sep 20, 2000

I have some sql results coming out as a string when it is a bunch of numbers separated with a coma. (1,2,3). I need to insert this figures as separate numbers in separate rows into a table in a database. How do I split them and how do I input them. I tried using a loop and it works well in an asp page but I need to do that in sql.

JG

View 1 Replies View Related

Split Function With Cursor

Apr 7, 2008

Hi,
I am trying to write a stored procedure that takes a comma separated letter. I have a split function that returns the splitted letters. I have select some values from the tables in the database where the title starts with each splitted letter. I thought I should use cursor that contains each letter and in the while loop i put my select statement with the conditions.
Is this the correct way. Or are there any ideas for this?

thanks,

Regards,
shakthi

View 2 Replies View Related

Split Number From Nvarchar Fiels Sql Server 2005

Mar 31, 2008

Hi
i want to split the numbers from the varchar field(accc0001).
i want 0001 only. at the same time select max of that number+1.

friends can u help me on this .

View 2 Replies View Related

T-SQL (SS2K8) :: Split Function On The Basis Of Contact Number

Jan 9, 2015

Split function. I have records of multiple users, the last value of every record is a contact number (10 Digits- Numeric), I want a split function which can take the whole text and split the records on the basis of contact number.

In order words i want SQL to locate the contact number and move to the next record after that and so on till the end of the text.

create table
tbl_1
(txt varchar (max))

insert into tbl_1 values ('john asfasdf 535 summit ave franklin lks nj 15521 510_644_1079 na na 5,8/12 executive,
finance finance and planning far 5537 21133 8.25 126 ronald d hensor jr. 5575621596

[Code] .....

Output
john jimenez 535 summit ave franklin lks nj 15521 510_644_1079 na na 5,8/12 executive,finance finance and planning far 5537 21133 8.25 126 ronald d hensor jr. 5575621596
jeffrey galione 57 allen dr wayne nj 15810 562_434_0710 na na 5,8/12 executive, technical sales and support good 8137 91630 8.25 126 eileen oneal 8258364083

[Code] ....

View 6 Replies View Related

T-SQL (SS2K8) :: Split Function That Allows Multiple Character Delimiter

Mar 25, 2015

I have a table with a varchar column that is delimited by char(227)+char(228)
i.e.,

OrNo=7807ãäSeqNo=1ãäPStopType=PãäPCity=TillsonburgãäPSt=ONãäPZIP=N4G4J1ãäPAdr1=10 ROUSE STREETãäPAdr2=ãäPLat=42.8625ãäPLon=-80.7267ãäDStopType=DãäDCity=GaffneyãäDSt=SCãäDZIP=29341ãäDAdr1=121 PAN AMERICAN DRIVE

Looking for split function that accepts a multiple character value as a delimiter?

View 7 Replies View Related

Reporting Services :: Split Function Resulting In Error

Oct 7, 2015

I have a report that is using the following expression for one of the fields:

=Split(Fields!FromAccount.Value, " ")(1)

The format of the number is xxxxx-xxx xxxxxxxxxxxx

So the function is to grab the second section of numbers after the space. The query for this report can bring back 1 to many results which equals one to many pages.

I have an issue where the query returns three results. The first page will display the correct number, the second page displays #Error and the third displays the number.

When I run the query from Management Studio I see the numbers are as follows:

xxxxx-xxx  xxxxxxxxxxxx
xxxxx-xxx xxxxxxxxxxxx
xxxxx-xxx  xxxxxxxxxxxx

Note the first and and last lines have extra spaces which I thought would be the cause of the problem though I would've expected the #Error to appear on the first and third page rather than the second one.

When I remove the extra space for the first and third number all three pages display their values correctly.

However, there are many, many numbers in the table that have one to two spaces. These numbers are from a spreadsheet that is imported biweekly. So it was either I fix the spreadsheet before every import or I come up with a new expression to check for one or two spaces. This is what I came up with:

=IIF (Fields!FromAccount.Value.Contains("  "), Split(Fields!FromAccount.Value, "  ")(1),Split(Fields!FromAccount.Value, " ")(1))

Now, the first page displays the number correctly while the second and third page displays with the #Error. Basically I want to say if the value contains two spaces then split at the two spaces otherwise split at the one space.

View 3 Replies View Related

Split Function To Separate Comma Delimited Values Into A Table

Oct 21, 2012

I have a stored procedure that is passed two values. Both are strings representations of GUID values, the first is a single value, the second is a comma delimited string of values.In the stored procedure I call a split function to separate the comma delimited values into a table and this is used in my WHERE clause to filter my select results.This is an example:

Code:
SELECT
item.uiGUID as ItemGUID,
stores.strStoreName as Store,
location.strLocationName as Location
FROM tblItems as item
INNER JOIN tblStoreLocations as location
ON item.uiLocationGUID = location.uiGUID
INNER JOIN tblStores as stores
ON location.uiStoreGUID = stores.uiGUID
WHERE CAST(item.uiGUID as varchar(36)) IN (SELECT Value FROM dbo.Split(',',@ItemGUIDList))

When I run this query in the management studio, passing a list of 5 values in the second parameter, my results include one item for each of the 5 values. However, when I pass the parameters from my ASP project, (I've verified the values I think are being passed are indeed being passed), I only get one item.I believe the error is in my split function. Both split functions return the same results in the SQL management studio, but only one returns the correct results in the the ASP project.

When I use this version of the function it returns the correct table values to the calling application, but it chokes when the item list does not have a trailing comma. I figure that to be a bug in the SQL function.

Code:
CREATE FUNCTION [dbo].[Split]
( @Delimiter varchar(5),
@List varchar(8000)
)
RETURNS @TableOfValues table
( RowID smallint IDENTITY(1,1),
[Value] varchar(50)

[code]....

View 7 Replies View Related

ROW_NUMBER() Function Is Not Recognized In Store Procedure.(how To Add ROW_NUMBER() Function Into SQL SERVER 2005 DataBase Library )

Feb 4, 2008

Can anybody know ,how can we add  builtin functions(ROW_NUMBER()) of Sql Server 2005  into database library.
I get this error when i used into storeprocedure :
ROW_NUMBER() function is not recognized in store procedure.
i used MS SQL SERVER 2005 , so i think "ROW_FUNCTION()" is not in MS SQL SERVER 2005 database library.
I need to add that function into MS SQL SERVER 2005 database library.
Can anbody know how we can add that function into MS SQL SERVER 2005 database library?
 

View 4 Replies View Related

SQL Server 2005, SQL Server Mobile, SQL Server Management Studio. Unsupported HTTP Function Call

Sep 5, 2005

Hi All,

View 14 Replies View Related

SQL Server 2005 Lag Function

Jan 18, 2008



Hello,

Does SQL Server 2005 have anything like a "lag" function that, in a sigle query allow you to retrive a previous record? The syntax would be like:

SELECT
transactionid
,transactiondatetime
,amount
,amount + LAG(amount) OVER(ORDER BY transactiondatetime) balance
FROM
bankaccount


Thanks for any advice

View 12 Replies View Related

Connection To SQL Server Files (*.mdf) Require SQL Server Express 2005 To Function Properly.

Jun 10, 2007

I dont have the SQL EXPRESS installed instead I have SQL Standard Edition.
 I have two SQL Server instances installed.
 1- UserLT (this is sql 2000)2- UserLTSQL2005 (this is SQL 2005 named instance)
But when i try to add a database to my VS website project I get the following error:
Connection to SQL Server files (*.mdf) require SQL server express 2005 to function properly. please verify the installation of the component or download from the URL: go.microsoft.com/fwlink/?linkId=4925
I went in Tools>Opetions>DataBase tools>Data Connection>Sql Server Instance Name (blank for default)
and changed the "SQLEXPRESS" to "USERLTSQL2005".
But I still get the same error message. Any ideas how i can resolve this issue?

View 23 Replies View Related

Connection To SQL Server Files (*.mdf) Require SQL Server Express 2005 To Function Properly

Jan 11, 2006

hello,

i've installed SQL server 2005 express and Visual web developper 2005 express.

when i whant to create a database in VWD the following error occures:

connection to SQL Server files (*.mdf) require SQL server express 2005 to function properly. please verify the installation of the component or download from the URL: go.microsoft.com/fwlink/?linkId=49251

i searched the internet but can't find the solution, i already reinstalled my complete workstation but the problem stays.

please help!

View 9 Replies View Related

Dont Think Discretization Function Is Necessary On The Analysis Service Server In SQL Server 2005

Apr 28, 2006

Hi, all here,

I am just wondering about the Discretization function available on analysis service server (which can not actually discretize data into user-defined expressions) . Isnt it redundant ? I mean since users can discretize their data more meaningfully based on their own expressions in database engine of SQL Server 2005.

Thanks a lot.

View 1 Replies View Related

Sql Server 2005 GETDATE() Function

Apr 22, 2008

I have a small problem using the GETDATE() function from a JAVA program using the MS JDBC connector.

When I use the SQL Mangment Studio Express to execute this query:

SELECT GETDATE()
it returns 2008-04-22 16:25:03.690 which is OK !!

I want to get that same value using a Java program so I do that query but when I display it it shows as:

2008-04-22 and there is no time there !
I tried formatting the date to include time but it shows as: 04/22/2008 12:00:00 AM
So maybe the time isn´t there ?

This is the code i am using:

Statement st = con.createStatement();
String sql = "SELECT GETDATE()";
ResultSet result1 = st.executeQuery(sql);

result1.next();

Date today = result1.getDate(1);


Any help would be appreciated.

View 4 Replies View Related

Count Function: SQL Server 2005

May 16, 2008

is it possible to do a count on the same column but under different circumstances posting the results in two different result columns?

View 6 Replies View Related

VS2005 Error: Connection To SQL Server Files (*.mdf) Requires SQL Server Express 2005 To Function Properly.

Mar 6, 2008



Good Evening All,

I've serached this forum and Google'd for a resolution to this issue, to no avail. Here's the scenario:
I'm running VS 2005 on Windows Media Center laptop and need to create ASP.net membership for my web application built using VB. I have SQL Server Developer installed with instance name MSSQLSERVER. Previously, I uninstalled SQL Express and installed Developer edition and can now open and utilize Management Studio.

Now, when I try to create a new SQL Server database in my solution's App_Data directory, I receive the above error. I already changed instance name in VS2005 per Tools-Options-Database Tools-Data Connections to MSSQLSERVER.

Could someone provide me with a list of procedures to ensure proper setup of VS2005 with SQL Server Developer Edition?

Thanks much for your help.

View 5 Replies View Related

SQL Server 2005 Query/trigger/function (whatever It Is That I Need)

Dec 8, 2006

Hey guys maybe you can help me out, been trying to figure this one out all day at work. I know how to use columns in a table to calculate another column in that same table. But I need to do some math on columns from a totally seperate table. Here is my scenario
 table 1 = stock table
 table 2 = Purchase order table
 in table 2 there are line items that have ordered quantities for parts that we have ordered
 in table 1 under each part number is a field for "quantity on order"
I need to compute the "quantity on order" in table 1 by summing all of the quantities in table 2 where the partnumber = the partnumber from table 1
 
quantity on order (table 1) = sum of all quantities (table 2) where the part numbers match
so for part number 516 i have this
 
table 2
poNumber             partNumber                 quantity
1                             516                             1
2                             516                             12
3                             516                             4
 
table 1
partNumber            inStock              onOrder
516                          0                        17(this is what i am trying to figure out how to compute)
 
any help on this qould be appreciated. I would like the database to automatically do this itself if at all possible.

View 3 Replies View Related

How To Run User Defined Function On Sql Server 2005

Dec 24, 2007

Dear all
I wants to run sql server user defined function when linked two server.
 
I have linked two sql server.There is one function called getenc().This function created on first server.What i want.I wants to run this user defined function on the second sql server. can any one help me?
 
Regards
Jerminxxx

View 7 Replies View Related

SQL Server 2005 Query With Date Function

Feb 5, 2008

I wrote a function and a SQL to get the  3 columns Date,Total Orders
& Amount, for dates between Date Started and Date Completed if I
pass different Dates in the SQL I get the correct result but if I pass
same dates then I don't get the result I am looking for .For Instance,if I give Date From=1/02/2008 ;Date To=1/8/2008(Different dates )I am getting values for all the three columns.But I give same dates for  Date From=01/02/2008 ;Date To=01/02/2008 then I am not getting the records.Some how I could not trace what could be the error in my SQL /Function.I appreciate if I could get some work around for this.Thanks!  Function:create function dbo.CreateDateList(@start datetime, @end datetime)returns @t table ( [date] datetime )asbegin if @start is null or @end is null return if @start > @end return set @start = convert(datetime, convert(varchar(10), @start, 120), 120) set @end = convert(datetime, convert(varchar(10), @end, 120), 120) while @start < @end begin insert into @t ( [date] ) values (@start) set @start = dateadd(day, 1, @start) end returnend ---------SELECT qUERY---------- SELECT Convert(Varchar(15), l.[date],101)as Date,COUNT(o.OrderID ) AS TotalOrders,ISNULL(Round(SUM(o.SubTotal),2),0) AS Amount , 1 as OrderByCol FROM dbo.CreateDateList(@DateFrom , @DateTo) l LEFT OUTER JOIN orders o ON o.Datecompleted >=Convert(Datetime, l.[date],101) and o.Datecompleted < dateadd(day,1,convert(Datetime, l.[date],101)) WHERE StoreID=@StoreID GROUP BY Convert(Varchar(15), l.[date],101) Union SELECT 'Grand Total' as Total,NULL AS TotalOrders, ISNULL(Round(SUM(o.SubTotal),2),0) AS Amount, 2 as OrderByCol FROM dbo.CreateDateList(@DateFrom , @DateTo) l LEFT OUTER JOIN orders o ON o.Datecompleted >=Convert(Datetime, l.[date],101) and o.Datecompleted < dateadd(day,1,convert(Datetime, l.[date],101)) WHERE StoreID=@StoreID Order by Date   

View 6 Replies View Related

Does SQL Server 2005 Has Similar Function Like Mysql_fetch_row ?

Mar 13, 2008

I just began to use SQL Server 2005 as database programming and
found out that I have to translate mysql_fetch_row into SQL Server 2005
but I cannot find some related functions/api, and I was wondering
Does SQL Server 2005 has similar function like mysql_fetch_row ?
Or if not, any advice how I can program to acheive similar functions ?
thank you in advance.

View 4 Replies View Related

EMERGENCY:rollback Function For Sql Server 2005?

Mar 13, 2008

is there a roll back function for sql server 2005 that would change data back to what it was before the execution of last update query?

View 8 Replies View Related

How To Read CSV File In SQL Server 2005 Using OpenRowSet Function

May 4, 2007

Hi

i want to access a CSV file using OpenRowSet function in SQL Server 2005.



Anyone having any idea; would be of great help.

Regards,

Salman Shehbaz.

View 8 Replies View Related

How To Create Assembly Function Using Dll Files In SQL Server 2005???

Aug 21, 2007

Hiiiiiiii all

I have to make a user defined function in c# as the class liberary and create a dll file, now i want to use this function in SQL Server 2005 as a part of CLR Integration

I have tried like this


CREATE ASSEMBLY abc
FROM 'C:abc.dll'

WITH PERMISSION_SET = SAFE

but it gives me
incorrect syntax error
so plzzzzz anyone help me wht to do in my probbbbbbbbb???????

Pratik Kansara

View 13 Replies View Related

SQL Server 2005 SELECT MAX Function For Multiple Columns On The Same Record

Aug 25, 2006

Hello,

I am trying to figure out how to use the select maximum command in SQL Server 2005. I have already created a database and I have it populate it with multiple fields and multiple records. I Would like to create a new column or field which contains the maximum value from four of the fields. I have already created a column and I am trying to figure out how to use a command or SQL statement which is entered into the computed equation or formula in the properties for this field/column.

Any help you can provide will be greatly appreciated!

Thank you,
Nathan

View 17 Replies View Related

ODBC Link From Access To SQL Server 2005 Stored Function

Sep 20, 2006

If I define a table-valued function in a SQL Server 2005 database, can I link to it from Access 2003 using ODBC?

I've defined the function successfully, and I can link from Access to tables in the database (so my ODBC link is basically functioning), but I can't see the table-valued function in the Linked Table Manager in Access.

I can define a pass-through query to grab the table, but with a pass-through query I have to provide the ODBC password every time.

What am I missing?

Suggestions?

View 1 Replies View Related

Trying To Split My Columns Into Years (col1 Must Have Vals For 2005, Col2 Vals For 2006)

Jan 26, 2007

Hi, i'm reasonably new to reporting services and am looking for a way to split my reports' Years to compare the months in year 2005 to 2006 but i can't get my data nest to one another in a single line, it splits the years into different rows

as an example this is what i want if you can decipher that
















2005
2006
Growth
2005 Year to Date
2006 Year to Date
Year to Date Growth




turnover
gross profit
turnover
gross profit
turnover
gross profit
turnover
gross profit










Jan
250500
75300
280200
84100
11.85629
11.686587
250500
75300










Feb
205000
67950
190350
59900
-7.14634
-11.84695
455500
143250
take the month above and add the
current months values


Mar
217670
70540
234200
78000
7.594064
10.57556
673170
213790










Apr
270780
84000
290400
93000
7.245735
10.714286
943950
297790










May
265000
79260
289050
90200
9.075472
13.802675
1208950
377050










Jun
277300
81050
277900
82000
0.216372
1.172116
1486250
458100










Jul


























Aug


























Sep


























Oct


























Nov


























Dec



























Here is my Query:

SELECT /*DT.[YEAR],*DT.[MONTH],*DT.MONTH_NAME,*/ DC.CLIENT_KEY, (select SUM(FT.Cost)where dt.[year] = 2005) AS COST , (select SUM(FT.Price)where dt.[year] = 2005)AS SALES,(select SUM(FT.Cost) where dt.[year] = 2006),(select SUM(FT.Price) where dt.[year] = 2006)--, SUM(FT.QTY) AS QUANTITY, SUM(FT.PRICE) - SUM(FT.COST) AS GP,(SUM(FT.PRICE) - SUM(FT.COST)) / SUM(FT.PRICE) * 100 AS GP_PERCENTAGEFROM FACT_TRANSACTION FT, DIM_TIME DT, DIM_CLIENT DC, DIM_INVOICE_TYPE DIT, DIM_PRODUCT DPWHERE FT.TIME_KEY = DT.TIME_KEYAND FT.PRODUCT_KEY = DP.PRODUCT_KEYAND FT.CLIENT_KEY = DC.CLIENT_KEYAND FT.TYPE_KEY = DIT.TYPE_KEY AND DIT.TYPE_KEY NOT IN (5,6,13,14,15,16,17)AND DC.CLIENT_SERIALNO = '86634'--AND DT.[YEAR] IN(2005,2006)AND DT.[MONTH] IN(1,2,3,4,5,6,7,8,9,10,11,12)AND DP.PRODUCT_KEY <> 1668684GROUP BY DT.[YEAR],DC.CLIENT_KEY--, DT.[MONTH]ORDER BY /*DT.[YEAR],*/DT.[MONTH]
but it returns everything under one another

2005 1 January 2005 3 296092.3431 405263.62 12811 109171.2769 26.93
2005 2 February 2005 3 318597.658 432098.17 13220 113500.512 26.26
2005 3 March 2005 3 371327.721 506481.46 15283 135153.739 26.68
2005 4 April 2005 3 371647.994 504713.99 15491 133065.996 26.36
2005 5 May 2005 3 400870.6138 542759.57 16296 141888.9562 26.14
2005 6 June 2005 3 399673.0086 546110.59 16607 146437.5814 26.81
2005 7 July 2005 3 390477.7521 535531.40 16153 145053.6479 27.08
2005 8 August 2005 3 380628.57 520281.87 15800 139653.30 26.84
2005 9 September 2005 3 340949.8849 471861.17 14820 130911.2851 27.74
2005 10 October 2005 3 340240.804 470007.78 14444 129766.976 27.60
2005 11 November 2005 3 349156.1871 481193.61 14523 132037.4229 27.43
2005 12 December 2005 3 346038.5059 477011.72 14865 130973.2141 27.45
2006 1 January 2006 3 340062.1369 470010.08 14037 129947.9431 27.64
2006 2 February 2006 3 328463.9689 452404.79 13996 123940.8211 27.39
2006 3 March 2006 3 375264.977 517800.27 16065 142535.293 27.52
2006 4 April 2006 3 412708.965 567014.52 17550 154305.555 27.21
2006 5 May 2006 3 446973.4231 606476.26 18920 159502.8369 26.29
2006 6 June 2006 3 406072.4943 544634.77 17053 138562.2757 25.44
2006 7 July 2006 3 389104.6316 526091.14 16228 136986.5084 26.03
2006 8 August 2006 3 317810.4531 431530.58 13641 113720.1269 26.35
2006 10 October 2006 3 405230.7083 549310.72 17151 144080.0117 26.22
2006 11 November 2006 3 379788.6645 514554.14 15917 134765.4755 26.19
2006 12 December 2006 3 393235.0906 531582.69 16924 138347.5994 26.02

If i do get them split then it put every year's value on a different line

2005   1234123.34    32432432.43   NULL   NULL
2006   NULL               NULL           12312.212   15235453.21

Please Help,

View 1 Replies View Related

How To Split One Coloumn Into Two Coloumns In Sql Server 2000

Oct 22, 2007

I have one table 'tbUser' having coloumnsUserID,UserName,Category   UserID      UserName    Category      1           Shailaja        H     2           Anagha         H     3           Raju              L     4           Kiran             L  I want output as  UserID      UserName    HigherCategory  LowerCategory      1           Shailaja        H     2           Anagha         H     3           Raju                                         L     4           Kiran                                        L 

View 1 Replies View Related

SQL Server 2014 :: Split And Transform Words

May 1, 2015

I have an application I write a textbox: 'SQL SQL' MICROSOFT 'SQL SQL'

When I click a button, I wanted to receive as stored procedure parameter:

@ String = 'SQL SQL "OR MICROSOFT OR MICROSOFT OR' SQL SQL '

View 2 Replies View Related

SQL Server 2008 :: Split Apart Filenames Into A Database?

Oct 11, 2015

I am trying to break apart a list of filenames that was inserted into a database. It only breaks out the first one then moves onto the next record. If I do them individually then seem to work but not the whole table when queried. I need to break out each file into a temp table then insert them into a documents field in a database.

my filenames look like so and can have from 1 file name to 10 file names in the string.

test.pdf,test2.pdf,test4.tif,test5.pdf
somedoc.tif,test.docx,test4.pdf

This is my current method, I needed to create a cursor around it to go through all the records, split out the filenames and insert into a temp table. But if there is a better way ill do it. The problem with this is only the first file is getting inserted into the temp table and nothing else even if the filename has 4 files in it.

Create table #tempFiles (OldStrId int, OldPercent int, strfilename varchar(max), RequestId int, OblId int)
declare @OldStr int, @OldPer int, @FileName varchar(max), @intcount int;
Declare filenames CURSOR FOR Select intSTRBonusID, intPercentID, strFileName from tblSTR where strFileName > ''
UNION ALL
Select intSTRBonusID, intPercentID, strFileName from tblSTRHist where intPercentID in (61,62) and strFileName > ''

[code]....

View 2 Replies View Related







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