.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Kaviya Balasubramanian
Sgraph Infotech
Imran Ghani
Post New Web Links

insert result of stored procedure in new table

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :Sql Server
 
hi how can i insert the result of stored procedure in the new table. Best Regards. Morteza


View Complete Post


More Related Resource Links

How do I insert values into different colunms but same row in a table using stored procedure

  
Hi everyone, I wish to create a scenario whereby my Stored Procedure will be able to do an Insert values into two colunms but single row of a table. For instance: AS BEGIN INSERT INTO Table1 (Message1, Number1) VALUES(@Message1, @Number1) END When I do the above stored procedure using SQL Express, and Excecute the stored procedure in VS2005 C# using ADO.Net, the table is updated but the values of Message1 and Number1 are inserted into different rows i.e. when value is inserted into Message1, Number1 is '0' and vice-versa. what I really want is for both Message1 and Number1 to be inserted with values at the same row. How do I acheive this please? Many thanks in advance.

How do I insert values into different colunms but same row in a table using stored procedure

  
Hi everyone, I wish to create a scenario whereby my Stored Procedure will be able to do an Insert values into two colunms but single row of a table. For instance: AS BEGIN INSERT INTO Table1 (Message1, Number1) VALUES(@Message1, @Number1) END When I do the above stored procedure using SQL Express, and Excecute the stored procedure in VS2005 C# using ADO.Net, the table is updated but the values of Message1 and Number1 are inserted into different rows i.e. when value is inserted into Message1, Number1 is '0' and vice-versa. what I really want is for both Message1 and Number1 to be inserted with values at the same row. How do I acheive this please? Many thanks in advance.

Insert ID field into SQL table programatically from Stored Procedure

  

Hi,

I have a table in SQL where I insert data (CatCodes) using C# code but I want to insert ID code (DealerID) with it as well. Following is my Stored Procedure and C# code:

PROCEDURE [dbo].[InfoInsert]
	-- Add the parameters for the stored procedure here
	@UserId uniqueidentifier,
	@Title char(32),
	@FirstName char(32),
	@LastName char(32),
	@CompanyName char(32),
	@Email char(32),
	@DealerID int OUTPUT
	
	
	
	
AS
BEGIN
SET NOCOUNT ON

	INSERT INTO [tblDealers] ([UserId], [Title], [FirstName], [LastName], [CompanyName], Email) 
        VALUES (@UserId, @Title, @FirstName, @LastName, @CompanyName, @Email)
        
        select @DealerID = SCOPE_IDENTITY()
        
       
       
END


 

C#:

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            

            
         
            
            //Insert membership and personal data
            TextBox UserNameTextBox = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
            SqlDataSource DataSource = (SqlDataSource)CreateUserWizardStep1.ContentTemplateContainer.FindControl("InsertExtraInfo");
           
            

            

            Membership

DTA doesn't find referenced table form stored procedure with SP_executesql

  
Using the SQL2008R2 profiler and DTA connected to a SQL2000 server. I created a tuning tracefile with profiler for a certain db on the sql2000 server because I need to tune 1 table in the database referenced by 3 parameterized stored procedures which built a query depending on the parameters and is executed with an sp_executesql statement. When I run the DTA loading the tracefile I see the exec stored procedure events with it's parameters and the message Event does not reference any tables. And that's it. The DTA generates no Recommendatioin at all. How can I get the exact sql statements in the tracefile so the DTA can do what he needs to do? Regards

how to include a user defined table type as input for stored procedure

  
Hi ,  I have a user defined table type which i need to pass as input parameter to the stored procedure .How can i do that?

Insert the results of a stored procedure into specific columns

  
Hello, I'm trying to update a table with values from a stored procedure. Here is what I've got: Open My_Cursor DECLARE @username varchar(200), @add1 varchar(200), @add2 varchar(200), @city varchar(200), @st varchar(200), @zip varchar(200) Fetch NEXT FROM MY_Cursor INTO @username WHILE @@FETCH_STATUS = 0 BEGIN insert into sheet1$ (f19,f20,f21,f22,f23) EXEC [dbo].[GetPrimaryEEsAddress] @dependentUsername = @username WHERE username = @username FETCH NEXT FROM MY_Cursor INTO @username END Getting error: Msg 156, Level 15, State 1, Line 11 Incorrect syntax near the keyword 'WHERE'.

Accessing table in DBO schema from Stored Procedure in other Schema

  
I am experiencing a strange issue related to schema qualification at a customer. No matter what we've tried we cannot recreate the issue internally. I am hoping someone can help. We create a Stored Procedure on a schema called "Import". In this stored procedure, we have numerous references to tables on the "dbo" schema, but we have not qualified them (I know this is not best practice, but it's legacy code and we're not going to change it right now). This has been used at other customers without issue. This one new customer is getting an issue where it does not seem to find the dbo table when trying to create the stored procedure. If we take the query out of a stored proceure and just run it as a T-SQL script, it works. So, the code below works select * from Import.Dirsync a join Inventory i on a.Audit_InventoryID = i.InventoryID But this does not. It complains that the column "InventoryID" on the table "Inventory" does not exist. create procedure Import.Test as select * from Import.Dirsync a join Inventory i on a.Audit_InventoryID = i.InventoryID My understanding is that any object on the dbo schema will be resolved. Again, this is working on all other servers with our databases. Any suggestions? Thanks Craig Bryden - Please mark correct answers

Stored Procedure utilizing table variable

  
I'm creating a stored procedure that will take the results of a temp table and check for existence using the IN keyword.  The code looks like this: ALTER PROCEDURE [dbo].[studentBranchLogin] -- Add the parameters for the stored procedure here @userName varchar(50), @userPass varchar(20) AS BEGIN DECLARE @dActive bit; DECLARE @TT TABLE (dept int, active bit); -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; INSERT INTO @TT(dept, active) SELECT deptid, active FROM srcuDeptId WHERE active = TRUE -- Insert statements for procedure here SELECT srcuid FROM srcuLogins WHERE logon = @userName AND password = @userPass AND srcuid IN @TT END I get a Msg 170, Level 15 state 1 Line 24: Incorrect syntax near '@TT'. So while I'm sure the @TT temp table isn't being read, I find very few resources for answer what the proper syntax should be.   Any assistance is greatly appreciated.

Passing Table Variable to Stored Procedure

  
My stored procedure expects a uniqueidentifier as a parameter.  However, this unique identifier is stored in a table variable, which looks like this:DECLARE @TableGiftGuid table ( GiftGuid uniqueidentifier )When I try to execute a stored procedure by passing the GiftGuid like so:EXEC my_procedure (SELECT GiftGuid FROM @TableGiftGuid) I get an error. What I ended up doing is declaring another variable, storing the GiftGuid into it and then passing the variable to the stored procedure like this: DECLARE @TableGiftGuid table ( GiftGuid uniqueidentifier ) DECLARE @GiftGuid uniqueidentifieDECLARE @TableGiftGuid table ( GiftGuid uniqueidentifier ) DECLARE @GiftGuid uniqueidentifier SET @GiftGuid = (SELECT GiftGuid FROM @TableGiftGuid) EXEC my_procedure @GiftGuidThat works, but is there a more elegant way of doing this?

Cannot call Table Valued Function from Dynamic stored procedure statement

  
Hello,  I have a table-valued function that splits string into a table column. I can easily call this function from a stored procedure within a regular SELECT statement: SELECT * FROM Table1 WHERE Code1 = '1' AND Code2 IN(SELECT * FROM [dbo].[fnSplitValues](@Code2String))   However when I try to use the same logic for a dynamic SELECT statement: ‘SELECT * FROM Table1 WHERE Code1 = '1' AND Code2 IN(SELECT * FROM ' + [dbo].[fnSplitValues](@Code2String) + ')’ I get an error ‘Cannot find either column "dbo" or the user-defined function or aggregate "dbo.fnSplitValues", or the name is ambiguous.’ Any idea what is wrong with my dynamic SQL?   Please help, Lana

Managing TypedDataSets when there is a change in backend Table / Stored Procedure / Database schema

  
Hi All, I am just curious to know if there is any easier way to synchronize the TypedDataSets with the chages made to backend Table / Stored Procedure schema.  I use Typed DataSets in my project extensively and I found them very useful and easier to code, but difficult to maintain  The difficuly I have always faced is whenever there is a change in a backend database table structure or stored procedure that is linked to any of the Typed DataSet in our project requires to recreate whole DataSet again by scrapping the old one. The backend changes will not be reflected unless and untill you recreate the whole stuff again. Is there any easier way to synchronize those typed datasets with the changes made to backend database schema or any other workaround that will not required to recreate the whole DataSet again.Hope above question makes sense. Any ideas.

Its posible to do a select without the table and the column names into a stored procedure?

  

Hello!!

I need your help. Imagine that I have two tables:

  1. ALUMN wich has three columns: IdAlumn, Name and Address.
  2. SPORT wich has columns: IdSport, Name, Players and Description.

Supose that my tables could be differnced by a number 1 is for ALUMN and 2 is for SPORT.

And the columns of each table too. So 1 is for IdAlumn, 2 is for Name and 3 is for Address. 1 is for IdSport, 2 is for Name 3 is for Players and 4 is for Description.

For example the combination of table 2 and column 3 is SPORT-Players.

Then I want to do an stored procedure that receives two parameters (the table, the column) @tab and&

Stored procedure and table value function

  

I have a function called F_TBL_VALS_FROM_STRING this function returns a table and uses '|' as a delimiter to distinguish between values.
this function is used in a procedure (bellow), while I've tested this function and it returns the requested values, using it in this stored procedure does not work.

ALTER PROCEDURE dbo.mytestproc
  (
    @doorList     varchar(4000),
    --From Date
    @FromDateYear   int,
    @FromDateMonth  int,
    @FromDateDay   int,
    --To Date
    @ToDateYear    int,
    @ToDateMonth   int,
    @ToDateDay    int,
    --From Time
    @FromTimeHour   int,
    @FromTimeMinute  int,
    @FromTimeSecond  int,
    --To Time
    @ToTimeHour     int,
    @ToTimeMinute   int,
    @ToTimeSecond   

How to display the contents of a table while debugging a stored procedure

  

I see that after a call to my stored procedure I am jumping into a trigger while trying to insert rows. How do I see what SELECT * FROM INSERTED is or what is in other tables while I am debugging my stored procedure. (I know I can put SELECT * FROM INSERTED into my trigger, etc. but I am looking to be able to debug my stored procedure without changing anything except things in my debug environment.


stored procedure or table adapter commands

  

hi friends

in my windows application i used a dataset and populated it with tables by dragging tables from server explorer, and for each table's table adapter i added four stored procedures that i have created in sql server while dataset generator generates insert, update , select , delete commands for each table adapter. i want to know whick one is better, using stored procedure or using dataset generated commands?

tanks in advance

 


GridView Insert clicking a button in footer row using stored procedure

  

Hi!! I need your help again.

I have a gridview with a button in the first column of the footer row and some controls (textbox, dropdowlist...) in the rest of the columns. I want to click that button and insert into a database table using an stored procedure the text properties of the controls in the other columns.

I don't know what's wrong... could you help me or post me a link to read it??

I'm setting the insert command with my stored procedure, I'm setting the storedprocedure as the insertcommandtype, I'm able to load the controls with correct values, but finally when I click the insert button that's not work!!!!

Thank you!!!


What is the best way to get the primary key column name of a table in a stored procedure ?

  
Hi,

I'm writing a stored procedure which manipulates a table whose name must be given as a parameter. The stored procedure needs the primary key column name (by design the primary key must have only one column), and I thought I could get this from the system table instead of having to provide it as a parameter. So I need to put the primary key column name in a variable.

The best way I found so far is this :

declare @keyname nvarchar(1024)
create
table #keys (table_qualifier nvarchar(255),table_owner nvarchar(255),table_name nvarchar

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend