Of course, this example can easily be expanded to include other attributes of the customer as well, such as the customer Name or perhaps a customer type. But perhaps changing the customer status is more than a simple UPDATE, and it involves updating multiple tables in the database, archiving data, sending notifications, and so on
Dan Wahlin - Passing an Array of Values to a Stored Procedure in SQL Server 2005
dwahlin - Friday, February 23, 2007 8:22:35 AM The XML serialization method sounds nice and ill probably use it myself but it ties the business layer into the data layer. Multiple objects with multiple properties could be passed in as XML and then parsed and inserted, deleted or updated with a single sproc rather than making multiple calls like many apps seem to do
pass table name as a parameter in stored procedure
Once concatenated, this new string is sent to the exec command, which runs the string as if it had been typed as a statement.I also changed the type of @tablename from varchar(500) to sysname
License This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL) Share email twitter facebook linkedin reddit google+ About the Author Prakash Lekhak Software Developer United States No Biography provided You may also be interested in... we have used try and catch block here if there is any error with database connection or inserting data then we are redirecting the user to Error.aspx page and closing the connection object from final block
Another alternative which I prefer is actually in the stored proc if you have a helper function that converts a CSV to a table, then you are able to join on that which is much safer than just sending the input directly to the query. Fill in your details below or click an icon to log in: Email (required) (Address never made public) Name (required) Website You are commenting using your WordPress.com account
It then parses the parameter, extracts individual OrderIDs from the comma separated list, inserts the OrderIDs into a table variable, and then joins the table variable with the main Orders table, to get the requested results. It then parses the parameter, in just one query, using the number table (unlike WHILE loop in previous examples) and joins the individual OrderIDs to the OrderIDs from Orders table to retrieve the results
SQL Server: how to get a database name as a parameter in a stored procedure - Stack Overflow
This has the advantage of limiting the databases that the proc can access to a known set, rather than allowing access anything and everything that the user account has rights to. In my opinion, the only acceptable use is a code generator, or some sort of database analysis tool which cannot know the required information ahead of time
SQL Server Stored Procedures - Fundamentals - SQL Server Performance
I have been studying from a high level SQL developer in order to understand SQL better and he very much confused me with the very advanced code that he was using. Truly appreciate you! Best regards, Patrick Billy Howell Reply June 14, 2012 at 7:56 pm Unfortunately, far more complex stored procedures have been written, Bryan, but I will walk through it quickly
In case, we consider the situation displayed in the table above, we should use the first stored procedure only once for adding the data in the dbo.Sales table. Fill in your details below or click an icon to log in: Email (required) (Address never made public) Name (required) Website You are commenting using your WordPress.com account
For my application, procedure 2 (and 3 and 4) used the output from procedure 1, but the main calling procedure executed procedures 3-4 before procedure 1 was completed. Please note that this is a simple example, the matter of the fact, we can do the task of these two stored procedure in a single SP but our goal of this blog post is to understand how we can pass the result of one SP to another SP as a parameter
No comments:
Post a Comment