Author |
Topic |
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-07-19 : 09:33:16
|
Hi all,Does anyone have a clever way of consuming the output of PRINT statements from a sp? (In process)Say I have a script and it calls a stored proc and that proc spits out a message (using PRINT)is there any way I can consume that message into a variable?Ideally if there was a way I could pipe the output from the sp into a VARCHAR(MAX) or something...... Can't find much online about it.Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-07-19 : 09:54:25
|
maybe using dbcc outputbuffer?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-07-19 : 11:29:16
|
You I'm trying to do it inside sql.... I *could* write an ado.net wrapper but I really don't want to have to.Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-07-19 : 11:29:58
|
I guess I could write a clr function that calls the sp and does something with the output....gahhh!Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-07-19 : 12:01:29
|
dbcc outputbuffer shoould give it but there is a limit to how much data it holds and you will probably want to reformat it.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-07-19 : 12:09:41
|
I don't think I can call DBCC OUTPUTBUFFER.What I'm trying to do is (inside the same batch)1) Call a sp2) Trap the results of that sp.....I think I'd need to have some sort of watcher polling outputbuffer on it to use given this context..Looks like I should be doing this outside the db..Or just change a spiderweb of 3rd party sps to do some sort of sensible logging.Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-07-19 : 12:19:32
|
ah no I seeI can call the sp and then call OUTPUTBUFFER on my own process.....ok....So doing something like *this* is possibleUSE tempdbGOCREATE PROCEDURE fooAS BEGIN PRINT 'Hi There World. I''m a completely annoying message that is vital somehow and you don''t know it yet. HAHAHA'ENDGO And then in another batch:EXEC fooDECLARE @output TABLE ([Buffer] VARCHAR(MAX))INSERT @outputEXEC ('DBCC OUTPUTBUFFER(@@SPID)')SELECT * FROM @output Will produce some nice stuff (256 row(s) affected)Buffer------------------------------------------------------------------------------00000000 04 01 00 d5 00 65 07 00 ab 22 01 00 00 00 00 01 ...Õ.e..«"......00000010 00 69 00 48 00 69 00 20 00 54 00 68 00 65 00 72 .i.H.i. .T.h.e.r00000020 00 65 00 20 00 57 00 6f 00 72 00 6c 00 64 00 2e .e. .W.o.r.l.d..00000030 00 20 00 49 00 27 00 6d 00 20 00 61 00 20 00 63 . .I.'.m. .a. .c00000040 00 6f 00 6d 00 70 00 6c 00 65 00 74 00 65 00 6c .o.m.p.l.e.t.e.l00000050 00 79 00 20 00 61 00 6e 00 6e 00 6f 00 79 00 69 .y. .a.n.n.o.y.i00000060 00 6e 00 67 00 20 00 6d 00 65 00 73 00 73 00 61 .n.g. .m.e.s.s.a00000070 00 67 00 65 00 20 00 74 00 68 00 61 00 74 00 20 .g.e. .t.h.a.t. 00000080 00 69 00 73 00 20 00 76 00 69 00 74 00 61 00 6c .i.s. .v.i.t.a.l00000090 00 20 00 73 00 6f 00 6d 00 65 00 68 00 6f 00 77 . .s.o.m.e.h.o.w000000a0 00 20 00 61 00 6e 00 64 00 20 00 79 00 6f 00 75 . .a.n.d. .y.o.u000000b0 00 20 00 64 00 6f 00 6e 00 27 00 74 00 20 00 6b . .d.o.n.'.t. .k000000c0 00 6e 00 6f 00 77 00 20 00 69 00 74 00 20 00 79 .n.o.w. .i.t. .y000000d0 00 65 00 74 00 2e 00 20 00 48 00 41 00 48 00 41 .e.t... .H.A.H.A000000e0 00 48 00 41 00 1e 53 00 4b 00 59 00 53 00 43 00 .H.A. Cheers Nigel.Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
 |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-07-19 : 12:20:28
|
you know this may actually be the weirdest hack I've seen with sqlserver yet. Grats!Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/ |
 |
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-07-19 : 12:21:10
|
As long as the spid is available dbcc outputbuffer shoould get the result of the sp.Not saying it's a good solution though - I've only implemented it once. For a critical task - and that was to get whatever info I could to troubleshoot errors.try thiscreate proc testasprint 'hello there'goexec testdbcc outputbuffer (@@spid)Would only use it in desperation.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-07-19 : 12:49:04
|
quote: Originally posted by Transact CharlieUSE tempdbGOCREATE PROCEDURE fooAS BEGIN PRINT 'Hi There World. I''m a completely annoying message that is vital somehow and you don''t know it yet. HAHAHA'ENDGO Transact CharlieMsg 3903.. The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION. http://nosqlsolution.blogspot.co.uk/
You really should not put in actual production code as an example like that How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|