Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Is it possible to add a clause to a Stored Procedure when calling it from your code; C#? I have Stored Procedure for which I need to add the clause "FOR XML AUTO" or "FOR XML RAW", but I do not have write access to change since its our clients stored procedure. I know the easiest would be to have them change it, however, I do not want to give up on creating our own solution first.

Any ideas?
Posted
Comments
RedDk 19-Aug-13 12:55pm    
Which is it "RAW" or "AUTO"?
iCanDivideByZero 19-Aug-13 13:01pm    
AUTO
pradiprenushe 19-Aug-13 13:00pm    
Not possible,
1.Create new sp add with same defination & add clause into that OR
2. Create if else logic iin sp one will existing & one with you clause
iCanDivideByZero 19-Aug-13 13:01pm    
Are there no other options available then?
pradiprenushe 19-Aug-13 13:03pm    
1.Create new sp add with same defination & add clause into that OR
2. Create if else logic iin sp one will existing & one with you clause
So no problem to existing application also

Yes you can do this using result of existing sp. Hope this will be helpful
SQL
DECLARE @cache TABLE (CountCol int NOT NULL)
INSERT @cache EXECUTE usp_Yoursp @Id=123
SELECT CountCol FROM @cache FOR XML AUTO
 
Share this answer
 
v3
Comments
iCanDivideByZero 19-Aug-13 15:42pm    
hmmmm...i tried your idea and received the following error.

Column name or number of supplied values does not match table definition. Could not find stored procedure 'CountCol'


Any clue to what is causing this?
pradiprenushe 20-Aug-13 0:21am    
Check output of sp & create table variable according to that. I have tried it & it is working.
pradiprenushe 20-Aug-13 0:49am    
If your sp returning ID then create table variable with id column

DECLARE @cache TABLE (id int NOT NULL)

INSERT @cache EXECUTE testsp

SELECT id FROM @cache FOR XML AUTO
iCanDivideByZero 20-Aug-13 10:36am    
Dude! That is exactly what I am looking for, Thanks! The output from this very closely matches the SQLXML output I have to match up to.
iCanDivideByZero 21-Aug-13 7:58am    
Quick question. Can you declare the @cache TABLE without specifying the id or the colums for the table?
Prepare an SQL as follows to call SP and return the result as XML. Then call this SQL from C#.

e.g.
select * from SPName() for xml auto
 
Share this answer
 
Comments
iCanDivideByZero 20-Aug-13 8:21am    
Could you please elaborate on this technique, I'm a bit of a noob

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900