From artful at rogers.com Tue Mar 13 11:35:06 2007 From: artful at rogers.com (artful at rogers.com) Date: Tue, 13 Mar 2007 09:35:06 -0700 (PDT) Subject: [dba-SQLServer] A UDF to turn a list into a table Message-ID: <20070313163506.42602.qmail@web88210.mail.re2.yahoo.com> I just dug up some code I wrote a long while back, because suddenly I needed it. It's a function that parses a comma-delimited string and places the contents into a table, then returns the table. Lots of front ends assemble a string and then pass it to a stored procedure or function that then uses the string as the argument to an IN() clause. This is woefully inefficient, and there is a better way. The following function does what is described above. The cool thing is that you can join the result table to some other table, with a significant performance gain over the typical IN() approach. Here is the function, followed by an example call: CREATE FUNCTION dbo.StringToTable_fnt ( @String varchar(100) ) RETURNS @Values TABLE (ID int primary key) AS BEGIN DECLARE @pos int DECLARE @value int WHILE @string > '' BEGIN SET @pos = CHARINDEX(',', @string) IF @pos > 0 BEGIN SET @value = SUBSTRING( @string, 1, @pos - 1) SELECT @string = LTRIM(SUBSTRING( @string, @pos + 1, LEN(@string)- at pos+1)) INSERT @Values SELECT @value END ELSE IF LEN(@string) > 0 BEGIN SET @value = @string INSERT @Values SELECT @value SET @string = '' END ELSE SET @string = '' END RETURN END -- SELECT * FROM dbo.StringToTable_fnt('100, 200, 300, 400, 500') Don't mind the formatting. I pasted it directly from SSMS. You can clean it up. Hope this helps someone, Arthur Fuller Technical Writer, Data Modeler, SQL Sensei Artful Databases Organization www.artfulsoftware.com From accessd at shaw.ca Tue Mar 13 11:54:09 2007 From: accessd at shaw.ca (Jim Lawrence) Date: Tue, 13 Mar 2007 08:54:09 -0800 Subject: [dba-SQLServer] A UDF to turn a list into a table In-Reply-To: <20070313163506.42602.qmail@web88210.mail.re2.yahoo.com> Message-ID: <0JEU009NCPGFMIH0@l-daemon> Hi Arthur: Cool... Do you mind if I store that piece of code for later use. Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of artful at rogers.com Sent: Tuesday, March 13, 2007 8:35 AM To: dba-SQLServer Subject: [dba-SQLServer] A UDF to turn a list into a table I just dug up some code I wrote a long while back, because suddenly I needed it. It's a function that parses a comma-delimited string and places the contents into a table, then returns the table. Lots of front ends assemble a string and then pass it to a stored procedure or function that then uses the string as the argument to an IN() clause. This is woefully inefficient, and there is a better way. The following function does what is described above. The cool thing is that you can join the result table to some other table, with a significant performance gain over the typical IN() approach. Here is the function, followed by an example call: CREATE FUNCTION dbo.StringToTable_fnt ( @String varchar(100) ) RETURNS @Values TABLE (ID int primary key) AS BEGIN DECLARE @pos int DECLARE @value int WHILE @string > '' BEGIN SET @pos = CHARINDEX(',', @string) IF @pos > 0 BEGIN SET @value = SUBSTRING( @string, 1, @pos - 1) SELECT @string = LTRIM(SUBSTRING( @string, @pos + 1, LEN(@string)- at pos+1)) INSERT @Values SELECT @value END ELSE IF LEN(@string) > 0 BEGIN SET @value = @string INSERT @Values SELECT @value SET @string = '' END ELSE SET @string = '' END RETURN END -- SELECT * FROM dbo.StringToTable_fnt('100, 200, 300, 400, 500') Don't mind the formatting. I pasted it directly from SSMS. You can clean it up. Hope this helps someone, Arthur Fuller Technical Writer, Data Modeler, SQL Sensei Artful Databases Organization www.artfulsoftware.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From fhtapia at gmail.com Tue Mar 13 13:16:54 2007 From: fhtapia at gmail.com (Francisco Tapia) Date: Tue, 13 Mar 2007 11:16:54 -0700 Subject: [dba-SQLServer] A UDF to turn a list into a table In-Reply-To: <20070313163506.42602.qmail@web88210.mail.re2.yahoo.com> References: <20070313163506.42602.qmail@web88210.mail.re2.yahoo.com> Message-ID: It's very similar to mine :) http://sqlthis.blogspot.com/2005/02/list-to-table.html On 3/13/07, artful at rogers.com wrote: > I just dug up some code I wrote a long while back, because suddenly I needed it. It's a function that parses a comma-delimited string and places the contents into a table, then returns the table. > > Lots of front ends assemble a string and then pass it to a stored procedure or function that then uses the string as the argument to an IN() clause. This is woefully inefficient, and there is a better way. The following function does what is described above. The cool thing is that you can join the result table to some other table, with a significant performance gain over the typical IN() approach. > > Here is the function, followed by an example call: > > > CREATE FUNCTION dbo.StringToTable_fnt > ( > @String varchar(100) > ) > RETURNS @Values TABLE (ID int primary key) > AS > BEGIN > DECLARE @pos int > DECLARE @value int > WHILE @string > '' > BEGIN > SET @pos = CHARINDEX(',', @string) > IF @pos > 0 > BEGIN > SET @value = SUBSTRING( @string, 1, @pos - 1) > SELECT @string = LTRIM(SUBSTRING( @string, @pos + 1, LEN(@string)- at pos+1)) > INSERT @Values SELECT @value > END > ELSE > IF LEN(@string) > 0 > BEGIN > SET @value = @string > INSERT @Values SELECT @value > SET @string = '' > END > ELSE > SET @string = '' > END > RETURN > END > -- SELECT * FROM dbo.StringToTable_fnt('100, 200, 300, 400, 500') > > > Don't mind the formatting. I pasted it directly from SSMS. You can clean it up. > > Hope this helps someone, > Arthur Fuller > Technical Writer, Data Modeler, SQL Sensei > Artful Databases Organization > www.artfulsoftware.com > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From artful at rogers.com Tue Mar 13 15:17:15 2007 From: artful at rogers.com (artful at rogers.com) Date: Tue, 13 Mar 2007 13:17:15 -0700 (PDT) Subject: [dba-SQLServer] A UDF to turn a list into a table Message-ID: <879507.59992.qm@web88214.mail.re2.yahoo.com> Of course not, silly! That's why I posted it. Arthur ----- Original Message ---- From: Jim Lawrence To: dba-sqlserver at databaseadvisors.com Sent: Tuesday, March 13, 2007 12:54:09 PM Subject: Re: [dba-SQLServer] A UDF to turn a list into a table Hi Arthur: Cool... Do you mind if I store that piece of code for later use. Jim From fhtapia at gmail.com Thu Mar 15 16:34:16 2007 From: fhtapia at gmail.com (Francisco Tapia) Date: Thu, 15 Mar 2007 14:34:16 -0700 Subject: [dba-SQLServer] Securables in SQL Server 2005 In-Reply-To: <1C2084FD2472124AB1812A5476EA3B7A0104E5E5@msgswbmnmsp04.wellsfargo.com> References: <1C2084FD2472124AB1812A5476EA3B7A0104E5E5@msgswbmnmsp04.wellsfargo.com> Message-ID: Elizabeth, Sorry for not replying before... I've been really busy for the last 2 months... I didn't see anyone reply to your message either. I have opted to set permissions using the query window now, this saves me on having to exercise my mouse hand. Generally it looks something like this: GRANT SELECT, INSERT, UPDATE ON vw_SomeView TO SomeRole On 2/7/07, Elizabeth.J.Doering at wellsfargo.com wrote: > > Dear List, > > I hope you can rescue the last of my hair--I've been pulling it out today in large handfuls! > > In SQL Server 2000, setting permissions for specific roles to be able to execute specific sprocs was a simple operation--boring, but simple. You were shown a list of all the objects you might grant or revoke permissions on and you could arrow and space bar through the list. > > In 2005, setting permissions for securables for specific roles is a nasty mouse intensive project. You're shown a list of available objects, with possible specific permissions in a separate list below. You select one on the top level, then mouse down to the bottom to click a permission there. And when you have done it all and click ok, the list vanishes completely. > > Will someone please tell me that I am missing something and that there is an easier way? And then, also, what the easier way is? :) > > Thanks so much! > > Liz > > > > > > Liz Doering > 612.667.2447 > > "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation" > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... From Elizabeth.J.Doering at wellsfargo.com Fri Mar 16 08:15:40 2007 From: Elizabeth.J.Doering at wellsfargo.com (Elizabeth.J.Doering at wellsfargo.com) Date: Fri, 16 Mar 2007 08:15:40 -0500 Subject: [dba-SQLServer] Securables in SQL Server 2005 References: <1C2084FD2472124AB1812A5476EA3B7A0104E5E5@msgswbmnmsp04.wellsfargo.com> Message-ID: <1C2084FD2472124AB1812A5476EA3B7A014836EB@msgswbmnmsp04.wellsfargo.com> Francisco, Thanks so much for replying. I actually came to the same solution. Since, however, I had hundreds to set--and a bunch to unset--I created a table with all the objects and who needed permissions on each one. Then I built up all my Grant and Revoke statements in a query, pasted the results in a new query window and ran them all at once. I'm sure there were more elegant solutions, but this one did save my fingers--and my hair! Thanks, Liz Liz Doering 612.667.2447 "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation" -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco Tapia Sent: Thursday, March 15, 2007 4:34 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] Securables in SQL Server 2005 Elizabeth, Sorry for not replying before... I've been really busy for the last 2 months... I didn't see anyone reply to your message either. I have opted to set permissions using the query window now, this saves me on having to exercise my mouse hand. Generally it looks something like this: GRANT SELECT, INSERT, UPDATE ON vw_SomeView TO SomeRole On 2/7/07, Elizabeth.J.Doering at wellsfargo.com wrote: > > Dear List, > > I hope you can rescue the last of my hair--I've been pulling it out today in large handfuls! > > In SQL Server 2000, setting permissions for specific roles to be able to execute specific sprocs was a simple operation--boring, but simple. You were shown a list of all the objects you might grant or revoke permissions on and you could arrow and space bar through the list. > > In 2005, setting permissions for securables for specific roles is a nasty mouse intensive project. You're shown a list of available objects, with possible specific permissions in a separate list below. You select one on the top level, then mouse down to the bottom to click a permission there. And when you have done it all and click ok, the list vanishes completely. > > Will someone please tell me that I am missing something and that there > is an easier way? And then, also, what the easier way is? :) > > Thanks so much! > > Liz > > > > > > Liz Doering > 612.667.2447 > > "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation" > > > _______________________________________________ > dba-SQLServer mailing list > dba-SQLServer at databaseadvisors.com > http://databaseadvisors.com/mailman/listinfo/dba-sqlserver > http://www.databaseadvisors.com > > -- -Francisco http://sqlthis.blogspot.com | Tsql and More... _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From rl_stewart at highstream.net Fri Mar 16 14:07:44 2007 From: rl_stewart at highstream.net (Robert L. Stewart) Date: Fri, 16 Mar 2007 14:07:44 -0500 Subject: [dba-SQLServer] Securables in SQL Server 2005 In-Reply-To: References: Message-ID: <200703161913.l2GJDKU26945@databaseadvisors.com> Liz, Here is what I think will be a better solution next time you have this problem. This is an SP that you can add to a database and then run. You pass in the user/role that you want to grant EXECUTE rights to and it goes through the SPs and functions and grants the rights. At 01:00 PM 3/16/2007, you wrote: >Date: Fri, 16 Mar 2007 08:15:40 -0500 >From: >Subject: Re: [dba-SQLServer] Securables in SQL Server 2005 >To: >Message-ID: > ><1C2084FD2472124AB1812A5476EA3B7A014836EB at msgswbmnmsp04.wellsfargo.com> > >Content-Type: text/plain; charset="US-ASCII" > >Francisco, > >Thanks so much for replying. I actually came to the same solution. > >Since, however, I had hundreds to set--and a bunch to unset--I created a >table with all the objects and who needed permissions on each one. Then >I built up all my Grant and Revoke statements in a query, pasted the >results in a new query window and ran them all at once. I'm sure there >were more elegant solutions, but this one did save my fingers--and my >hair! > >Thanks, > >Liz From rl_stewart at highstream.net Fri Mar 16 14:14:58 2007 From: rl_stewart at highstream.net (Robert L. Stewart) Date: Fri, 16 Mar 2007 14:14:58 -0500 Subject: [dba-SQLServer] Securables in SQL Server 2005 Message-ID: <200703161917.l2GJH6U28033@databaseadvisors.com> Liz, Here is what I think will be a better solution next time you have this problem. This is an SP that you can add to a database and then run. You pass in the user/role that you want to grant EXECUTE rights to and it goes through the SPs and functions and grants the rights. (SQL 2005) CREATE PROCEDURE dbo.__SetProcPermissions @Role varchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @ProcName varchar(100), @ProcType varchar(100), @Sql varchar(1000) DECLARE cProcs CURSOR FOR SELECT sys.objects.name AS ProcName, sys.objects.type_desc AS ProcType FROM sys.objects WHERE type_desc = 'SQL_STORED_PROCEDURE' OR type_desc LIKE '%FUNCTION%' OPEN cProcs FETCH NEXT FROM cProcs INTO @ProcName, @ProcType WHILE (@@FETCH_STATUS = 0) -- it still is getting records BEGIN SELECT @Sql = 'GRANT EXECUTE ON ' + @ProcName + ' TO ' + @Role EXEC sp_ExecuteSQL @Sql IF (CHARINDEX(@ProcType,'FUNCTION', 1) > 0) BEGIN SELECT @Sql = 'GRANT REFRENCES ON ' + @ProcName + ' TO ' + @Role EXEC sp_ExecuteSQL @Sql END FETCH NEXT FROM cProcs INTO @ProcName, @ProcType END CLOSE cProcs DEALLOCATE cProcs END GO I guess it would help if I actually sent it. :-) Robert At 01:00 PM 3/16/2007, you wrote: >Date: Fri, 16 Mar 2007 08:15:40 -0500 >From: >Subject: Re: [dba-SQLServer] Securables in SQL Server 2005 >To: >Message-ID: > ><1C2084FD2472124AB1812A5476EA3B7A014836EB at msgswbmnmsp04.wellsfargo.com> > >Content-Type: text/plain; charset="US-ASCII" > >Francisco, > >Thanks so much for replying. I actually came to the same solution. > >Since, however, I had hundreds to set--and a bunch to unset--I created a >table with all the objects and who needed permissions on each one. Then >I built up all my Grant and Revoke statements in a query, pasted the >results in a new query window and ran them all at once. I'm sure there >were more elegant solutions, but this one did save my fingers--and my >hair! > >Thanks, > >Liz From Elizabeth.J.Doering at wellsfargo.com Fri Mar 16 16:34:25 2007 From: Elizabeth.J.Doering at wellsfargo.com (Elizabeth.J.Doering at wellsfargo.com) Date: Fri, 16 Mar 2007 16:34:25 -0500 Subject: [dba-SQLServer] Securables in SQL Server 2005 References: <200703161917.l2GJH6U28033@databaseadvisors.com> Message-ID: <1C2084FD2472124AB1812A5476EA3B7A01483876@msgswbmnmsp04.wellsfargo.com> Thanks Robert! Liz Liz Doering 612.667.2447 "This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose, or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. Thank you for your cooperation" -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Robert L. Stewart Sent: Friday, March 16, 2007 2:15 PM To: dba-sqlserver at databaseadvisors.com Cc: Doering, Elizabeth J. Subject: Re: [dba-SQLServer] Securables in SQL Server 2005 Liz, Here is what I think will be a better solution next time you have this problem. This is an SP that you can add to a database and then run. You pass in the user/role that you want to grant EXECUTE rights to and it goes through the SPs and functions and grants the rights. (SQL 2005) CREATE PROCEDURE dbo.__SetProcPermissions @Role varchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @ProcName varchar(100), @ProcType varchar(100), @Sql varchar(1000) DECLARE cProcs CURSOR FOR SELECT sys.objects.name AS ProcName, sys.objects.type_desc AS ProcType FROM sys.objects WHERE type_desc = 'SQL_STORED_PROCEDURE' OR type_desc LIKE '%FUNCTION%' OPEN cProcs FETCH NEXT FROM cProcs INTO @ProcName, @ProcType WHILE (@@FETCH_STATUS = 0) -- it still is getting records BEGIN SELECT @Sql = 'GRANT EXECUTE ON ' + @ProcName + ' TO ' + @Role EXEC sp_ExecuteSQL @Sql IF (CHARINDEX(@ProcType,'FUNCTION', 1) > 0) BEGIN SELECT @Sql = 'GRANT REFRENCES ON ' + @ProcName + ' TO ' + @Role EXEC sp_ExecuteSQL @Sql END FETCH NEXT FROM cProcs INTO @ProcName, @ProcType END CLOSE cProcs DEALLOCATE cProcs END GO I guess it would help if I actually sent it. :-) Robert At 01:00 PM 3/16/2007, you wrote: >Date: Fri, 16 Mar 2007 08:15:40 -0500 >From: >Subject: Re: [dba-SQLServer] Securables in SQL Server 2005 >To: >Message-ID: > ><1C2084FD2472124AB1812A5476EA3B7A014836EB at msgswbmnmsp04.wellsfargo.com> > >Content-Type: text/plain; charset="US-ASCII" > >Francisco, > >Thanks so much for replying. I actually came to the same solution. > >Since, however, I had hundreds to set--and a bunch to unset--I created >a table with all the objects and who needed permissions on each one. >Then I built up all my Grant and Revoke statements in a query, pasted >the results in a new query window and ran them all at once. I'm sure >there were more elegant solutions, but this one did save my >fingers--and my hair! > >Thanks, > >Liz _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Fri Mar 30 11:50:48 2007 From: jwcolby at colbyconsulting.com (JWColby) Date: Fri, 30 Mar 2007 12:50:48 -0400 Subject: [dba-SQLServer] SSIS packages Message-ID: <001001c772eb$91e47ce0$657aa8c0@m6805> I need to import 50+ text files into SQL Server. These are fixed width files with 150 fields. I tried to run the wizard and save an SSIS package, and in fact I do have an SSIS package however I cannot execute it. So that is my first issue, how is it that I can create a SSIS package and then not have it function when immediately re-executed? In fact I am not sure that this will help anyway since I would need to either specify a different file name or play stupid games renaming the source file. Is there an editor for SSIS packages to allow going into them and making modifications once created? 1) Is there ANY way to do this via the wizard, so that I can graphically define the column positions, and then save that definition and run it again later? 2) Can the wizard run this "something" that I saved. It seems rather silly that the wizard cannot simply look for something that it saved just moments before, load that something, and execute it. 3) It seems rather silly that after executing the wizard, you no longer have the ability to "go back", you have no choice but to continue, whereupon you have to go back through the whole rather painful process of setting up 150 fields. 4) Is there any way to set up the column NAMES in the destination table inside of the import wizard? With fixed with data there is no header row of field names as there might be in CSV format. SQL Server is simultaneously so powerful and so stupid sometimes! I just want to get work done! John W. Colby Colby Consulting www.ColbyConsulting.com From jlawrenc1 at shaw.ca Fri Mar 30 13:04:49 2007 From: jlawrenc1 at shaw.ca (Jim Lawrence) Date: Fri, 30 Mar 2007 11:04:49 -0700 Subject: [dba-SQLServer] SSIS packages In-Reply-To: <001001c772eb$91e47ce0$657aa8c0@m6805> Message-ID: <0JFQ002E1A1Q4XY1@l-daemon> Hi John: Have you looked at this link: http://support.microsoft.com/?kbid=918760 yet? Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of JWColby Sent: Friday, March 30, 2007 9:51 AM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] SSIS packages I need to import 50+ text files into SQL Server. These are fixed width files with 150 fields. I tried to run the wizard and save an SSIS package, and in fact I do have an SSIS package however I cannot execute it. So that is my first issue, how is it that I can create a SSIS package and then not have it function when immediately re-executed? In fact I am not sure that this will help anyway since I would need to either specify a different file name or play stupid games renaming the source file. Is there an editor for SSIS packages to allow going into them and making modifications once created? 1) Is there ANY way to do this via the wizard, so that I can graphically define the column positions, and then save that definition and run it again later? 2) Can the wizard run this "something" that I saved. It seems rather silly that the wizard cannot simply look for something that it saved just moments before, load that something, and execute it. 3) It seems rather silly that after executing the wizard, you no longer have the ability to "go back", you have no choice but to continue, whereupon you have to go back through the whole rather painful process of setting up 150 fields. 4) Is there any way to set up the column NAMES in the destination table inside of the import wizard? With fixed with data there is no header row of field names as there might be in CSV format. SQL Server is simultaneously so powerful and so stupid sometimes! I just want to get work done! John W. Colby Colby Consulting www.ColbyConsulting.com From markamatte at hotmail.com Fri Mar 30 13:31:56 2007 From: markamatte at hotmail.com (Mark A Matte) Date: Fri, 30 Mar 2007 18:31:56 +0000 Subject: [dba-SQLServer] SSIS packages In-Reply-To: <001001c772eb$91e47ce0$657aa8c0@m6805> Message-ID: John, I don't know how to solve the re-execute part of your problem...and I'm not sure if this will help with 50+ text files...but... I had 45 SQL statements to run against a number of different fields in a single table. I didn't want to have to sit there and push the button 45 times so I took all of the WHERE clauses and put them in a table...1 row per...I then looped through that table with the query analyzer. Each record was passed to a stored procedure that built and executed a SQL insert statement. With that in mind...could a SP be used to pass your file names to SSIS if you had them listed in a table? Not sure if its possible...I myself am still a newbie to SQL server. Good Luck, Mark A. Matte >From: "JWColby" >Reply-To: dba-sqlserver at databaseadvisors.com >To: >Subject: [dba-SQLServer] SSIS packages >Date: Fri, 30 Mar 2007 12:50:48 -0400 > >I need to import 50+ text files into SQL Server. These are fixed width >files with 150 fields. I tried to run the wizard and save an SSIS package, >and in fact I do have an SSIS package however I cannot execute it. So that >is my first issue, how is it that I can create a SSIS package and then not >have it function when immediately re-executed? > >In fact I am not sure that this will help anyway since I would need to >either specify a different file name or play stupid games renaming the >source file. Is there an editor for SSIS packages to allow going into them >and making modifications once created? > >1) Is there ANY way to do this via the wizard, so that I can graphically >define the column positions, and then save that definition and run it again >later? >2) Can the wizard run this "something" that I saved. It seems rather silly >that the wizard cannot simply look for something that it saved just moments >before, load that something, and execute it. >3) It seems rather silly that after executing the wizard, you no longer >have >the ability to "go back", you have no choice but to continue, whereupon you >have to go back through the whole rather painful process of setting up 150 >fields. >4) Is there any way to set up the column NAMES in the destination table >inside of the import wizard? With fixed with data there is no header row >of >field names as there might be in CSV format. > >SQL Server is simultaneously so powerful and so stupid sometimes! I just >want to get work done! > >John W. Colby >Colby Consulting >www.ColbyConsulting.com > >_______________________________________________ >dba-SQLServer mailing list >dba-SQLServer at databaseadvisors.com >http://databaseadvisors.com/mailman/listinfo/dba-sqlserver >http://www.databaseadvisors.com > _________________________________________________________________ Mortgage refinance is hot 1) Rates near 30-yr lows 2) Good credit get intro-rate 4.625%* https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h2a5f&s=4056&p=5117&disc=y&vers=743 From jwcolby at colbyconsulting.com Fri Mar 30 13:37:07 2007 From: jwcolby at colbyconsulting.com (JWColby) Date: Fri, 30 Mar 2007 14:37:07 -0400 Subject: [dba-SQLServer] SSIS packages In-Reply-To: <0JFQ002E1A1Q4XY1@l-daemon> References: <001001c772eb$91e47ce0$657aa8c0@m6805> <0JFQ002E1A1Q4XY1@l-daemon> Message-ID: <002a01c772fa$6bd24000$657aa8c0@m6805> Yea, I found that. In fact it isn't terribly helpful for a wide variety of reasons. A) My SQL Server uses windows login for everything. Since I only log in as myself... And I run everything as myself... B) I cannot seem to find a place to run the SSIS from inside of SQL Server management studio. I dunno, probably just me. C) I cannot seem to find a way to load the SSIS package from the wizard. That seems a natural thing to do but... I dunno, probably just me. D) When run from a double click the SSIS actually executes but gives about 46 bajillion errors, probably as is common, all related to the first error which is that the table does not exist in the database. NSS, the table is supposed to be CREATED by the SSIS, at least it was created by the setup in the wizard that created the SSIS. I dunno, probably just me. E) Even if I do manage to do that, I still need to edit the SSIS to either change the raw file name, or even add a list of raw file names. I did see a place in the wizard to specify many input files. So it seems obvious to me that I would find some way to edit the SSIS to allow modifying the file list, and even make it append to an existing table instead of creating a new table all the time. I dunno, probably just me. If I were going to build a wizard that allows the save to SSIS, the very first page of that same wizard would offer to open an existing SSIS for modification. I dunno, probably just me.... I just expected a wizard to be a tool for ignorant people and kind of cater to ignorant people. That's why I use it after all. My experience with Access tells me that folks who know the product rarely use the wizards. I went all the way through the wizard, defined 150 fields, ran to completion, it didn't do what I expected but DIDN'T OFFER TO BACK UP anymore, SAVED THE DAMNED SSIS, and now can't seem to do anything with it. Sigh. Unless I figure out how to work with the SSIS I am faced with an endless cycle of defining fields and testing, defining fields, testing... It's not like I don't have real work to do after all. I suppose this is just the dues I am expected to pay to play with the big boys. FYI, I decided to "edit" the SSIS package from explorer and Visual Studio opened. That does allow me to work with the VSS graphically, although I am again not sure how much use it will be. I feel like I stepped in quicksand. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: Friday, March 30, 2007 2:05 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages Hi John: Have you looked at this link: http://support.microsoft.com/?kbid=918760 yet? Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of JWColby Sent: Friday, March 30, 2007 9:51 AM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] SSIS packages I need to import 50+ text files into SQL Server. These are fixed width files with 150 fields. I tried to run the wizard and save an SSIS package, and in fact I do have an SSIS package however I cannot execute it. So that is my first issue, how is it that I can create a SSIS package and then not have it function when immediately re-executed? In fact I am not sure that this will help anyway since I would need to either specify a different file name or play stupid games renaming the source file. Is there an editor for SSIS packages to allow going into them and making modifications once created? 1) Is there ANY way to do this via the wizard, so that I can graphically define the column positions, and then save that definition and run it again later? 2) Can the wizard run this "something" that I saved. It seems rather silly that the wizard cannot simply look for something that it saved just moments before, load that something, and execute it. 3) It seems rather silly that after executing the wizard, you no longer have the ability to "go back", you have no choice but to continue, whereupon you have to go back through the whole rather painful process of setting up 150 fields. 4) Is there any way to set up the column NAMES in the destination table inside of the import wizard? With fixed with data there is no header row of field names as there might be in CSV format. SQL Server is simultaneously so powerful and so stupid sometimes! I just want to get work done! John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From James at fcidms.com Fri Mar 30 15:29:43 2007 From: James at fcidms.com (James Barash) Date: Fri, 30 Mar 2007 16:29:43 -0400 Subject: [dba-SQLServer] SSIS packages In-Reply-To: <002a01c772fa$6bd24000$657aa8c0@m6805> Message-ID: <00ea01c7730a$26ee09f0$800101df@fci.local> John: I had to do something very similar with SSIS and found the Wizard to virtually useless. Even when you do save the package, it seems to be designed in such a convoluted way that it is nearly impossible to modify in any meaningful way. What you need to do is use Visual Studio directly. There is a ForEach loop container that will, among other things, loop through all the files in a directory that match a filespec, and allow you to execute a DataFlow task for each file. You can use the DataFlow task to define the columns of your text files and map those to specific columns in a SQL table. The Help file does have an example of how to do this. I can't say I like the Visual Studio interface, maybe I'm just used to the SQL Server 2000 dts designer, but it will do everything you need, and can be very powerful, but I have found it difficult to learn. Good luck and I hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of JWColby Sent: Friday, March 30, 2007 2:37 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages Yea, I found that. In fact it isn't terribly helpful for a wide variety of reasons. A) My SQL Server uses windows login for everything. Since I only log in as myself... And I run everything as myself... B) I cannot seem to find a place to run the SSIS from inside of SQL Server management studio. I dunno, probably just me. C) I cannot seem to find a way to load the SSIS package from the wizard. That seems a natural thing to do but... I dunno, probably just me. D) When run from a double click the SSIS actually executes but gives about 46 bajillion errors, probably as is common, all related to the first error which is that the table does not exist in the database. NSS, the table is supposed to be CREATED by the SSIS, at least it was created by the setup in the wizard that created the SSIS. I dunno, probably just me. E) Even if I do manage to do that, I still need to edit the SSIS to either change the raw file name, or even add a list of raw file names. I did see a place in the wizard to specify many input files. So it seems obvious to me that I would find some way to edit the SSIS to allow modifying the file list, and even make it append to an existing table instead of creating a new table all the time. I dunno, probably just me. If I were going to build a wizard that allows the save to SSIS, the very first page of that same wizard would offer to open an existing SSIS for modification. I dunno, probably just me.... I just expected a wizard to be a tool for ignorant people and kind of cater to ignorant people. That's why I use it after all. My experience with Access tells me that folks who know the product rarely use the wizards. I went all the way through the wizard, defined 150 fields, ran to completion, it didn't do what I expected but DIDN'T OFFER TO BACK UP anymore, SAVED THE DAMNED SSIS, and now can't seem to do anything with it. Sigh. Unless I figure out how to work with the SSIS I am faced with an endless cycle of defining fields and testing, defining fields, testing... It's not like I don't have real work to do after all. I suppose this is just the dues I am expected to pay to play with the big boys. FYI, I decided to "edit" the SSIS package from explorer and Visual Studio opened. That does allow me to work with the VSS graphically, although I am again not sure how much use it will be. I feel like I stepped in quicksand. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: Friday, March 30, 2007 2:05 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages Hi John: Have you looked at this link: http://support.microsoft.com/?kbid=918760 yet? Jim -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of JWColby Sent: Friday, March 30, 2007 9:51 AM To: dba-sqlserver at databaseadvisors.com Subject: [dba-SQLServer] SSIS packages I need to import 50+ text files into SQL Server. These are fixed width files with 150 fields. I tried to run the wizard and save an SSIS package, and in fact I do have an SSIS package however I cannot execute it. So that is my first issue, how is it that I can create a SSIS package and then not have it function when immediately re-executed? In fact I am not sure that this will help anyway since I would need to either specify a different file name or play stupid games renaming the source file. Is there an editor for SSIS packages to allow going into them and making modifications once created? 1) Is there ANY way to do this via the wizard, so that I can graphically define the column positions, and then save that definition and run it again later? 2) Can the wizard run this "something" that I saved. It seems rather silly that the wizard cannot simply look for something that it saved just moments before, load that something, and execute it. 3) It seems rather silly that after executing the wizard, you no longer have the ability to "go back", you have no choice but to continue, whereupon you have to go back through the whole rather painful process of setting up 150 fields. 4) Is there any way to set up the column NAMES in the destination table inside of the import wizard? With fixed with data there is no header row of field names as there might be in CSV format. SQL Server is simultaneously so powerful and so stupid sometimes! I just want to get work done! John W. Colby Colby Consulting www.ColbyConsulting.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Fri Mar 30 15:40:35 2007 From: jwcolby at colbyconsulting.com (JWColby) Date: Fri, 30 Mar 2007 16:40:35 -0400 Subject: [dba-SQLServer] SSIS packages In-Reply-To: <00ea01c7730a$26ee09f0$800101df@fci.local> References: <002a01c772fa$6bd24000$657aa8c0@m6805> <00ea01c7730a$26ee09f0$800101df@fci.local> Message-ID: <002c01c7730b$ab82a990$657aa8c0@m6805> James, Thanks for that. I opened the SSIS directly in an editor and it is XML of sorts. It didn't look like it was going to be easy to work with though. Something like an iterator through a directory sounds just right. The problem of course is that I am not up to speed on VB.Net by any stretch of the imagination. Still, given example code I might actually manage that. The SSIS looks like it was designed to be used directly in .NET though. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Friday, March 30, 2007 4:30 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages John: I had to do something very similar with SSIS and found the Wizard to virtually useless. Even when you do save the package, it seems to be designed in such a convoluted way that it is nearly impossible to modify in any meaningful way. What you need to do is use Visual Studio directly. There is a ForEach loop container that will, among other things, loop through all the files in a directory that match a filespec, and allow you to execute a DataFlow task for each file. You can use the DataFlow task to define the columns of your text files and map those to specific columns in a SQL table. The Help file does have an example of how to do this. I can't say I like the Visual Studio interface, maybe I'm just used to the SQL Server 2000 dts designer, but it will do everything you need, and can be very powerful, but I have found it difficult to learn. Good luck and I hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of JWColby Sent: Friday, March 30, 2007 2:37 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages Yea, I found that. In fact it isn't terribly helpful for a wide variety of reasons. A) My SQL Server uses windows login for everything. Since I only log in as myself... And I run everything as myself... B) I cannot seem to find a place to run the SSIS from inside of SQL Server management studio. I dunno, probably just me. C) I cannot seem to find a way to load the SSIS package from the wizard. That seems a natural thing to do but... I dunno, probably just me. D) When run from a double click the SSIS actually executes but gives about 46 bajillion errors, probably as is common, all related to the first error which is that the table does not exist in the database. NSS, the table is supposed to be CREATED by the SSIS, at least it was created by the setup in the wizard that created the SSIS. I dunno, probably just me. E) Even if I do manage to do that, I still need to edit the SSIS to either change the raw file name, or even add a list of raw file names. I did see a place in the wizard to specify many input files. So it seems obvious to me that I would find some way to edit the SSIS to allow modifying the file list, and even make it append to an existing table instead of creating a new table all the time. I dunno, probably just me. If I were going to build a wizard that allows the save to SSIS, the very first page of that same wizard would offer to open an existing SSIS for modification. I dunno, probably just me.... I just expected a wizard to be a tool for ignorant people and kind of cater to ignorant people. That's why I use it after all. My experience with Access tells me that folks who know the product rarely use the wizards. I went all the way through the wizard, defined 150 fields, ran to completion, it didn't do what I expected but DIDN'T OFFER TO BACK UP anymore, SAVED THE DAMNED SSIS, and now can't seem to do anything with it. Sigh. Unless I figure out how to work with the SSIS I am faced with an endless cycle of defining fields and testing, defining fields, testing... It's not like I don't have real work to do after all. I suppose this is just the dues I am expected to pay to play with the big boys. FYI, I decided to "edit" the SSIS package from explorer and Visual Studio opened. That does allow me to work with the VSS graphically, although I am again not sure how much use it will be. I feel like I stepped in quicksand. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: Friday, March 30, 2007 2:05 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages Hi John: Have you looked at this link: http://support.microsoft.com/?kbid=918760 yet? Jim From James at fcidms.com Fri Mar 30 15:57:04 2007 From: James at fcidms.com (James Barash) Date: Fri, 30 Mar 2007 16:57:04 -0400 Subject: [dba-SQLServer] SSIS packages In-Reply-To: <002c01c7730b$ab82a990$657aa8c0@m6805> Message-ID: <00ec01c7730d$f8c493b0$800101df@fci.local> John: The Visual Studio that comes with SQL Server 2005 is a subset of .NET so you don't need to be conversant with VB.NET to use it. It is a graphical development system so you shouldn't need to get into the gritty details, like editing the xml or writing .NET code. You can do everything by dragging the appropriate objects onto a canvass and setting the necessary properties. Open Visual Studio and create a new Business Intelligence/Integration Services Project. Then Search the Help for ForEach and that should get you started. The key pieces are setting up the appropriate Connection Manager objects and learning how to use Expressions. Expression are how the ForEach container passes the file names to the Connection Objects. It did take me a long time to get used to it and whenever I don't use it for a few weeks, I feel like I'm starting over since nothing seems intuitive but it can be very powerful. James -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of JWColby Sent: Friday, March 30, 2007 4:41 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages James, Thanks for that. I opened the SSIS directly in an editor and it is XML of sorts. It didn't look like it was going to be easy to work with though. Something like an iterator through a directory sounds just right. The problem of course is that I am not up to speed on VB.Net by any stretch of the imagination. Still, given example code I might actually manage that. The SSIS looks like it was designed to be used directly in .NET though. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of James Barash Sent: Friday, March 30, 2007 4:30 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages John: I had to do something very similar with SSIS and found the Wizard to virtually useless. Even when you do save the package, it seems to be designed in such a convoluted way that it is nearly impossible to modify in any meaningful way. What you need to do is use Visual Studio directly. There is a ForEach loop container that will, among other things, loop through all the files in a directory that match a filespec, and allow you to execute a DataFlow task for each file. You can use the DataFlow task to define the columns of your text files and map those to specific columns in a SQL table. The Help file does have an example of how to do this. I can't say I like the Visual Studio interface, maybe I'm just used to the SQL Server 2000 dts designer, but it will do everything you need, and can be very powerful, but I have found it difficult to learn. Good luck and I hope this helps. James Barash -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of JWColby Sent: Friday, March 30, 2007 2:37 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages Yea, I found that. In fact it isn't terribly helpful for a wide variety of reasons. A) My SQL Server uses windows login for everything. Since I only log in as myself... And I run everything as myself... B) I cannot seem to find a place to run the SSIS from inside of SQL Server management studio. I dunno, probably just me. C) I cannot seem to find a way to load the SSIS package from the wizard. That seems a natural thing to do but... I dunno, probably just me. D) When run from a double click the SSIS actually executes but gives about 46 bajillion errors, probably as is common, all related to the first error which is that the table does not exist in the database. NSS, the table is supposed to be CREATED by the SSIS, at least it was created by the setup in the wizard that created the SSIS. I dunno, probably just me. E) Even if I do manage to do that, I still need to edit the SSIS to either change the raw file name, or even add a list of raw file names. I did see a place in the wizard to specify many input files. So it seems obvious to me that I would find some way to edit the SSIS to allow modifying the file list, and even make it append to an existing table instead of creating a new table all the time. I dunno, probably just me. If I were going to build a wizard that allows the save to SSIS, the very first page of that same wizard would offer to open an existing SSIS for modification. I dunno, probably just me.... I just expected a wizard to be a tool for ignorant people and kind of cater to ignorant people. That's why I use it after all. My experience with Access tells me that folks who know the product rarely use the wizards. I went all the way through the wizard, defined 150 fields, ran to completion, it didn't do what I expected but DIDN'T OFFER TO BACK UP anymore, SAVED THE DAMNED SSIS, and now can't seem to do anything with it. Sigh. Unless I figure out how to work with the SSIS I am faced with an endless cycle of defining fields and testing, defining fields, testing... It's not like I don't have real work to do after all. I suppose this is just the dues I am expected to pay to play with the big boys. FYI, I decided to "edit" the SSIS package from explorer and Visual Studio opened. That does allow me to work with the VSS graphically, although I am again not sure how much use it will be. I feel like I stepped in quicksand. John W. Colby Colby Consulting www.ColbyConsulting.com -----Original Message----- From: dba-sqlserver-bounces at databaseadvisors.com [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Jim Lawrence Sent: Friday, March 30, 2007 2:05 PM To: dba-sqlserver at databaseadvisors.com Subject: Re: [dba-SQLServer] SSIS packages Hi John: Have you looked at this link: http://support.microsoft.com/?kbid=918760 yet? Jim _______________________________________________ dba-SQLServer mailing list dba-SQLServer at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/dba-sqlserver http://www.databaseadvisors.com From jwcolby at colbyconsulting.com Sat Mar 31 13:33:36 2007 From: jwcolby at colbyconsulting.com (JWColby) Date: Sat, 31 Mar 2007 14:33:36 -0400 Subject: [dba-SQLServer] SQL Server - Time only in date field Message-ID: <000501c773c3$1913bf50$657aa8c0@m6805> Can SQL Server handle a date with just a time portion in the field? IOW a date of 12:03 am without a date? John W. Colby Colby Consulting www.ColbyConsulting.com From stuart at lexacorp.com.pg Sat Mar 31 18:40:12 2007 From: stuart at lexacorp.com.pg (Stuart McLachlan) Date: Sun, 01 Apr 2007 09:40:12 +1000 Subject: [dba-SQLServer] SQL Server - Time only in date field In-Reply-To: <000501c773c3$1913bf50$657aa8c0@m6805> References: <000501c773c3$1913bf50$657aa8c0@m6805> Message-ID: <460EF15C.20162.130E4C0E@stuart.lexacorp.com.pg> On 31 Mar 2007 at 14:33, JWColby wrote: > Can SQL Server handle a date with just a time portion in the field? IOW a > date of 12:03 am without a date? Yes. Does it just the way that Access does. It defaults to date 0 if no date part is specified. Date 0 is January 1, 1900 To retrieve the time as a string use Convert(char(8),myDate,8) for hh:mm:ss or Convert(char(12),myDate,14) if you want milliseconds. (108 and114 return the same thing) -- Stuart