How do I return XML from a Stored Procedure?

First, SqlCommand has a ExecuteXmlReader method, not ExecuteXMlReader as you wrote (this is misspelling). Second, SqlCommand.ExecuteXmlReader method returns a value of type XmlReader, not a DataReader as is in your example. So changing your code to: using (XmlReader reader = cmd.ExecuteXmlReader()) { while(reader.Read()) { string s = reader.ReadOuterXml(); // do something with s } } … Read more

How do I execute a MS SQL Server stored procedure in java/jsp, returning table data?

Our server calls stored procs from Java like so – works on both SQL Server 2000 & 2008: String SPsql = “EXEC <sp_name> ?,?”; // for stored proc taking 2 parameters Connection con = SmartPoolFactory.getConnection(); // java.sql.Connection PreparedStatement ps = con.prepareStatement(SPsql); ps.setEscapeProcessing(true); ps.setQueryTimeout(<timeout value>); ps.setString(1, <param1>); ps.setString(2, <param2>); ResultSet rs = ps.executeQuery();

Dynamic order direction

You could have two near-identical ORDER BY items, one ASC and one DESC, and extend your CASE statement to make one or other of them always equal a single value: ORDER BY CASE WHEN @OrderDirection = 0 THEN 1 ELSE CASE WHEN @OrderByColumn = ‘AddedDate’ THEN CONVERT(varchar(50), AddedDate) WHEN @OrderByColumn = ‘Visible’ THEN CONVERT(varchar(2), Visible) … Read more

How to execute a stored procedure inside a select query

Thanks @twoleggedhorse. Here is the solution. First we created a function CREATE FUNCTION GetAIntFromStoredProc(@parm Nvarchar(50)) RETURNS INTEGER AS BEGIN DECLARE @id INTEGER set @id= (select TOP(1) id From tbl where col=@parm) RETURN @id END then we do the select query Select col1, col2, col3, GetAIntFromStoredProc(T.col1) As col4 From Tbl as T Where col2=@parm