﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server 2005 General Discussion  / Issue with OSQL / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 16:34:19 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Issue with OSQL</title><link>http://www.sqlservercentral.com/Forums/Topic1420985-149-1.aspx</link><description>[quote][b]Compassionate (3/5/2013)[/b][hr]No, @f1 has only underscore as the special character reamining all are letters/digits.Could you please explain more on RAISEERROR with sev 10?[/quote]You can add calls to RAISERROR with a severity of 10 or less which will send an informational message to the output stream.Here is a generic call that sends a literal string to the output stream:[code="sql"]RAISERROR('Custom informational message.', 10, 1);[/code]Another way to call RAISERROR that might be useful in your case is to use tokens to send variable values to the output stream, like this:RAISERROR('@f1 = %s', 10, 1, @f1);What's happening in the above statement is that the value of @f1 is being substituted into the place of the token %s, which means "a string value", within the message before it is sent to the output stream There is a different token for numbers, %d, and some other tokens for different data types as well. Unfortunately there is no token for date or time values.You can read more here:[u][url=http://msdn.microsoft.com/en-us/library/ms178592(v=sql.90).aspx]RAISERROR (Transact-SQL) - SQL Server 2005[/url][/u]</description><pubDate>Tue, 05 Mar 2013 09:09:00 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Issue with OSQL</title><link>http://www.sqlservercentral.com/Forums/Topic1420985-149-1.aspx</link><description>No, @f1 has only underscore as the special character reamining all are letters/digits.Could you please explain more on RAISEERROR with sev 10?</description><pubDate>Tue, 05 Mar 2013 04:11:35 GMT</pubDate><dc:creator>Compassionate</dc:creator></item><item><title>RE: Issue with OSQL</title><link>http://www.sqlservercentral.com/Forums/Topic1420985-149-1.aspx</link><description>Does @f1 ever have a character in it that would be considered invalid in a Windows file name?Do you know what I mean when I say add calls to "RAISERROR with severity 10"?</description><pubDate>Mon, 04 Mar 2013 06:37:01 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Issue with OSQL</title><link>http://www.sqlservercentral.com/Forums/Topic1420985-149-1.aspx</link><description>there would be values in C1 and T1 for sure.They never be null</description><pubDate>Mon, 04 Mar 2013 04:20:14 GMT</pubDate><dc:creator>Compassionate</dc:creator></item><item><title>RE: Issue with OSQL</title><link>http://www.sqlservercentral.com/Forums/Topic1420985-149-1.aspx</link><description>What comes to mind initially is that @cmd is sometimes ending up NULL due to @c1 or @t1 (coming from the cursor-select) being NULL since anything+NULL=NULL. Try adding some logging or some RAISERROR commands with severity=10 to see what @cmd is set to when it stops generating files.</description><pubDate>Sat, 02 Mar 2013 04:39:33 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Issue with OSQL</title><link>http://www.sqlservercentral.com/Forums/Topic1420985-149-1.aspx</link><description>sorry for the delay as i am not in town.below is the code snippet. on an average this cursor has to generate around 90 files and this cursor runs every 15min.----------------------------------------	declare my_cursor CURSOR for 			select distinct WRS.f1 , WRS.c1 from tab2 WCB			inner join tab1 WRS on WCB.c1=WRS.c1 	OPEN my_cursor	FETCH NEXT FROM my_cursor 	INTO @f1, @c1	WHILE @@FETCH_STATUS = 0	BEGIN				set @nvchProcedure = 'proc name' 		select @ts = convert(varchar, getdate(),112)+replace(convert(varchar, getdate(),108),':','') -- suffix the file name with datetimestamp						select @ff1 = @f1 + @ts + '.psv'			insert into tab3 (c1,f1,ff1)	values (@c1,@f1,@ff1)			SELECT @cmd = 'osql -S ' + @@servername +' -E -n -h-1 -w2500 -q "SET NOCOUNT ON EXEC ' + @HostDB + '.dbo.' + @nvchProcedure +' '''+@c1 +''''+',''''+'" -o "'+ @nvchFileLocation +@f1+@ts+'.psv'					EXEC master..xp_cmdshell @cmd							FETCH NEXT FROM my_cursor 		INTO @f1, @c1	END	CLOSE my_cursor	DEALLOCATE my_cursor----------------------------------------</description><pubDate>Sat, 02 Mar 2013 00:34:52 GMT</pubDate><dc:creator>Compassionate</dc:creator></item><item><title>RE: Issue with OSQL</title><link>http://www.sqlservercentral.com/Forums/Topic1420985-149-1.aspx</link><description>A few things:1) osql is deprecated in SQL 2005. Consider switching to use sqlcmd or bcp for this work. 2) accessing the file system from T-SQL can create some scenarios that are difficult to debug. Consider switching from running this process in a cursor in T-SQL to something in SSIS or PowerShell so you can move away from using xp_cmdshell. Moving in this direction could make item 1 moot since SSIS and PowerShell both have the ability to write to files natively, i.e. without the help of SQL Server command lines tools.3) We cannot see what you see. Please post the code that includes the cursor and the call to xp_cmdshell so we can see too. Make sure to cleanse any sensitive information from the code before posting including items in code comments and object names that may reveal company or personal information.</description><pubDate>Mon, 18 Feb 2013 06:54:28 GMT</pubDate><dc:creator>opc.three</dc:creator></item><item><title>RE: Issue with OSQL</title><link>http://www.sqlservercentral.com/Forums/Topic1420985-149-1.aspx</link><description>adding to the below, i am using sql server 2005.</description><pubDate>Sun, 17 Feb 2013 08:51:23 GMT</pubDate><dc:creator>Compassionate</dc:creator></item><item><title>Issue with OSQL</title><link>http://www.sqlservercentral.com/Forums/Topic1420985-149-1.aspx</link><description>Hi Friends,Requirement :  i have a table which contains around 40 columns of which name is a column which i use to segregate the data because the contains the data for multiple names. Extract data for a NAME and store that in a file in windows directory.what i did:i have written a stored proc to which i send NAME as a parameter.The proc extracts all the data for that NAME. So, i have used OSQL utility to generate the output in a file( should be generated in a windows directory). I have around 30 to 40 NAMES.So, i have a cursor which loops through the NAMES and calls OSQL for each and every NAME.OSQL command is assigned to a string variable and that string is passed as a parameter to xp_cmdshell.Issue: whatever i wrote after OSQL command(execute xp_cmdshell), not getting executed.Also, if i pass 40 NAMES , only 20 to 30 files are getting created and rest of the files are not getting generated at all.Please advise your valuable suggestion.</description><pubDate>Sun, 17 Feb 2013 08:49:59 GMT</pubDate><dc:creator>Compassionate</dc:creator></item></channel></rss>