Click here to Skip to main content
15,892,965 members
Home / Discussions / Database
   

Database

 
GeneralRe: Does PRINT work in sql server function Pin
Mycroft Holmes17-Aug-10 19:29
professionalMycroft Holmes17-Aug-10 19:29 
AnswerRe: Does PRINT work in sql server function Pin
David Skelly17-Aug-10 22:10
David Skelly17-Aug-10 22:10 
GeneralRe: Does PRINT work in sql server function Pin
Mycroft Holmes17-Aug-10 23:37
professionalMycroft Holmes17-Aug-10 23:37 
GeneralRe: Does PRINT work in sql server function Pin
Jagz W18-Aug-10 0:29
professionalJagz W18-Aug-10 0:29 
GeneralRe: Does PRINT work in sql server function Pin
Mycroft Holmes18-Aug-10 2:49
professionalMycroft Holmes18-Aug-10 2:49 
GeneralRe: Does PRINT work in sql server function Pin
Jagz W18-Aug-10 6:57
professionalJagz W18-Aug-10 6:57 
GeneralRe: Does PRINT work in sql server function Pin
David Skelly18-Aug-10 3:33
David Skelly18-Aug-10 3:33 
AnswerRe: Does PRINT work in sql server function Pin
Eddy Vluggen19-Aug-10 12:32
professionalEddy Vluggen19-Aug-10 12:32 
J walia wrote:
Does PRINT work in sql server function???


You can convert your prints to match something like below;
SQL
DECLARE @printz AS TABLE(
	 Stamp DATETIME DEFAULT GETDATE()
	,Msg NVARCHAR(MAX)
	)

INSERT INTO @printz(Msg) 
SELECT 'We are at the start of the proc'

-- Do bunch o' SQL here

INSERT INTO @printz(Msg) 
SELECT 'Something went terribly wrong here, eracing all evidence'

-- Print some more 

INSERT INTO @printz(Msg) 
SELECT 'We are at the end of the proc'

SELECT Stamp, Msg FROM @printz

Another option that I sometimes resort to, is the RAISERROR[^] statement. To test that it'll print both statements from a sproc;
C#
try
{
	using (System.Data.SqlClient.SqlConnection con = 
       new System.Data.SqlClient.SqlConnection(
       	"Server=.;Database=[YOURDBNAME];Trusted_Connection=True;"))
	using(var cmd = con.CreateCommand())
	{				
		con.Open();
		cmd.CommandText = "testerror";
		cmd.ExecuteNonQuery();
	}
}
catch(System.Data.SqlClient.SqlException ex)
{
	System.Diagnostics.Debug.Print(ex.ToString());
}

SQL
CREATE PROCEDURE TESTERROR AS
BEGIN
	RAISERROR (N'This is message %s %d.', -- Message text.
           18, -- Severity,
           1, -- State,
           N'number', -- First argument.
           5); -- Second argument.

	RAISERROR (N'This is message %s %d.', -- Message text.
           18, 
           1, 
           N'number', 
           6); 
END


Good luck Smile | :)
I are Troll Suspicious | :suss:

QuestionGet hirarchy query Pin
SatyaKeerthi1516-Aug-10 21:30
SatyaKeerthi1516-Aug-10 21:30 
AnswerRe: Get hirarchy query Pin
Blue_Boy16-Aug-10 22:19
Blue_Boy16-Aug-10 22:19 
GeneralRe: Get hirarchy query Pin
SatyaKeerthi1516-Aug-10 22:32
SatyaKeerthi1516-Aug-10 22:32 
AnswerRe: Get hirarchy query Pin
J4amieC16-Aug-10 22:35
J4amieC16-Aug-10 22:35 
GeneralRe: Get hirarchy query Pin
SatyaKeerthi1518-Aug-10 0:52
SatyaKeerthi1518-Aug-10 0:52 
GeneralRe: Get hirarchy query Pin
J4amieC18-Aug-10 4:52
J4amieC18-Aug-10 4:52 
AnswerRe: Get hirarchy query Pin
jayantbramhankar19-Aug-10 20:27
jayantbramhankar19-Aug-10 20:27 
AnswerRe: Get hirarchy query Pin
ScottM118-Aug-10 1:58
ScottM118-Aug-10 1:58 
GeneralRe: Get hirarchy query Pin
SatyaKeerthi1518-Aug-10 2:03
SatyaKeerthi1518-Aug-10 2:03 
GeneralRe: Get hirarchy query Pin
ScottM118-Aug-10 2:09
ScottM118-Aug-10 2:09 
GeneralRe: Get hirarchy query Pin
ScottM118-Aug-10 2:10
ScottM118-Aug-10 2:10 
GeneralRe: Get hirarchy query Pin
SatyaKeerthi1518-Aug-10 18:52
SatyaKeerthi1518-Aug-10 18:52 
GeneralRe: Get hirarchy query Pin
ScottM118-Aug-10 20:56
ScottM118-Aug-10 20:56 
GeneralRe: Get hirarchy query Pin
SatyaKeerthi1518-Aug-10 21:11
SatyaKeerthi1518-Aug-10 21:11 
GeneralRe: Get hirarchy query Pin
ScottM118-Aug-10 21:17
ScottM118-Aug-10 21:17 
GeneralRe: Get hirarchy query Pin
SatyaKeerthi1518-Aug-10 19:01
SatyaKeerthi1518-Aug-10 19:01 
QuestionGet hirarchy query Pin
SatyaKeerthi1518-Aug-10 19:02
SatyaKeerthi1518-Aug-10 19:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.