Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 BCP Out Column that is Varchar(MAX)

Author  Topic 

X002548
Not Just a Number

15586 Posts

Posted - 2011-06-15 : 13:36:40
When I do this to insert the parameter into a column that is varchar(max) as defined in the table



edit: the declare

DECLARE @s datetime,
@e datetime,
@Error_Type int,
@Error_Loc int,
@sprc int,
@Parameters varchar(MAX),
@Sprocname varchar(255),
@res_version int,
@res_cd int,
@path_id int,
@resource_count int,
@count int,
@count2 int,
@res_name varchar(255)

The DDL:

CREATE TABLE [dbo].[SprocExecLog](
[SprocName] [varchar](256) NOT NULL,
[TranStart] [datetime] NOT NULL,
[TranEnd] [datetime] NOT NULL,
[LogStart] [datetime] NOT NULL,
[LogEnd] [datetime] NOT NULL,
[ReturnCode] [int] NULL,
[ErrorCode] [int] NULL,
[ErrorMessage] [varchar](4000) NULL,
[Rows] [int] NOT NULL,
[App_User] [varchar](30) NOT NULL,
[Sys_User] [varchar](30) NOT NULL,
[User_Name] [varchar](30) NOT NULL,
[Host_Name] [varchar](256) NOT NULL,
[Parameters] [varchar](max) NULL
) ON [PRIMARY]


SET @Parameters = 'DECLARE @rc int, @Error int, @Error_Message varchar(255), @Rowcount int; '+CHAR(13)+CHAR(10)
+ 'EXEC ' + @SprocName +CHAR(13)+CHAR(10)
+ ' @DATA=' + COALESCE(CHAR(39)+@DATA+CHAR(39),'NULL')+CHAR(13)+CHAR(10)
+ ', @User=' + COALESCE(CHAR(39)+@User+CHAR(39),'NULL')+CHAR(13)+CHAR(10)
+ ', @rc=@rc OUTPUT, @Error=@Error OUTPUT, @Error_Message=@Error_Message OUTPUT, @Rowcount=@Rowcount OUTPUT; '+CHAR(13)+CHAR(10)
+ 'SELECT @rc AS [RC], @Error AS [Error], @Error_Message AS [Error_Message], @Rowcount AS [RowCount]'

EXEC [isp_LOG_SprocExecLog] @Sprocname, @s, @e, @rc, @Error, @Error_Message, @Rowcount, @User, @Parameters, @sprc OUTPUT



The results seem truncated.

When I check the table


SELECT TOP 1 LEN(Parameters)
FROM SprocExecLog
WHERE SprocName = 'USP_INS_ADMIN_DETAILS'
ORDER BY TranStart DESC


I get 4000

Any ideas why?

Is it a buffer thing?


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-15 : 13:40:34
Why is 4000 wrong?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-06-15 : 13:49:22
quote:
Originally posted by tkizer

Why is 4000 wrong?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



Because it's being truncated...I know the XML is longer

This is the Bozo code that wants to update like 40 tables at once...

I just what to see the XML they are passing him

And to figure out a way to clean this mess up

I know it's a time bomb waiting to explode

He is already taking over 3 seconds per insert with little or no data in the XML..if they really start with a massive set of XML...who knows

And what about if the DB is heavily populated...the inserts would slow down I don't think...

Logically what they are doing is insane...





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-15 : 14:22:48
Well we'll need to see the code in order to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-06-15 : 14:43:51
which code? The code above sets the parameter that is varchar(max)

It then exec a stored procedure that logs the sproc call

And I guess the missing piece is the bcp out...which works, but truncates the data



DECLARE @cmd varchar(8000)
SET @cmd =
' bcp '
+ '"SELECT TOP 1 Parameters'
+ ' FROM ISRS.dbo.SprocExecLog'
+ ' WHERE SprocName IN (''USP_INS_ADMIN_DETAILS_V2'', ''USP_INS_ADMIN_DETAILS'')'
+ ' ORDER BY TranStart DESC"'
+ ' queryout'
+ ' D:\SPROC_EXEC_XML.SQL'
+ ' -SNJROS1BBLD0304\DEV2K08'
+ ' -T'
+ ' -c'

SELECT @cmd

exec master..xp_cmdshell @cmd





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-06-15 : 14:48:37
See the parameter is set up to mimic the call for Manglement Studio

So when the developers complain "the database ain't working" I can show them their call and expailn the bozo things they are doing with out me 1). Having to believe in their mistaken lies, and 2). Me knot having to type in their mistaken inputs

It contains the declares the executes and a select of the output parameters



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2011-06-15 : 14:51:00
Brett - this might help - http://www.simple-talk.com/community/blogs/philfactor/archive/2007/07/13/33494.aspx


Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-06-16 : 15:01:04
oh what an idiot..the logging sproc was never updated to change the parameter @parameters fr4om nvarchar(4000) to varchar(max)

THAT's why it was only 4000 in the table

We are golden now

Idiot



DECLARE @cmd varchar(8000)
SET @cmd =
' bcp '
+ '"SELECT TOP 1 Parameters'
+ ' FROM ISRS.dbo.SprocExecLog'
+ ' WHERE SprocName IN (''USP_INS_ADMIN_DETAILS_V2'', ''USP_INS_ADMIN_DETAILS'')'
+ ' ORDER BY TranStart DESC"'
+ ' queryout'
+ ' D:\SPROC_EXEC_XML.SQL'
+ ' -SNJROS1BBLD0304\DEV2K08'
+ ' -T'
+ ' -w'

SELECT @cmd

exec master..xp_cmdshell @cmd

exec master..xp_cmdshell 'Dir D:\*.sql'

exec master..xp_cmdshell 'Copy D:\*.sql \\L-llrltenn\X002548_Sprocs\*.*'




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-06-16 : 15:22:44
That's why I had asked for the code. You posted all of the other code, but not the code for the logging sproc.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-06-16 : 18:45:47
quote:
Originally posted by tkizer

That's why I had asked for the code. You posted all of the other code, but not the code for the logging sproc.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



I'll use my Mulligan here...it's been a rough...few years



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -