J walia wrote:
Does PRINT work in sql server function???
You can convert your prints to match something like below;
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;
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());
}
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 :)
I are Troll :suss: