Tweeted twitter.com/StackDBAs/status/958700967070978048
5 deleted 11 characters in body; edited title
source | link

declaring Declaring cursor to loop over some values in SQL serverServer 2008 R2

I have some business unit such as India, International, US, UK. 

I have to:

  1. Create a table variable (virtual in-memory table) with columns that match SPROC SP_Reportstored procedure SP_Report resultset.
  2. Declare a cursor that contains all business units and then the cursor should loop over the BU's.
  3. For each BU, execute a stored procedure called SP_ReportSP_Report and insert the data into the table variable.
  4. Finally I have to select the columns from the table variable + timestamp + BU, insert them into another table and clear the table variable.

Code:


    declare @K table (BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money)
    declare @FY int
    declare @BU nvarchar(max)

    INSERT INTO @K
    (BU, K, Y, A, D, YP) 
    EXEC dbo.SP_Report '2012', 'India'

    SELECT * FROM @K

This code gives mereturns the result of the table variable. Now I have to use it cursor, which I don't know how to. How I can solve the same.

declaring cursor to loop over some values in SQL server 2008 R2

I have some business unit such as India, International, US, UK. I have to:

  1. Create a table variable (virtual in-memory table) with columns that match SPROC SP_Report resultset.
  2. Declare a cursor that contains all business units and then the cursor should loop over the BU's.
  3. For each BU, execute a stored procedure called SP_Report and insert the data into the table variable.
  4. Finally I have to select the columns from the table variable + timestamp + BU, insert them into another table and clear the table variable.

    declare @K table (BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money)
    declare @FY int
    declare @BU nvarchar(max)

    INSERT INTO @K
    (BU,K,Y,A,D,YP) 
    EXEC dbo.SP_Report '2012', 'India'

    SELECT * FROM @K

This code gives me the result of the table variable. Now I have to use it cursor, which I don't know how to. How I can solve the same.

Declaring cursor to loop over some values in SQL Server 2008 R2

I have some business unit such as India, International, US, UK. 

I have to:

  1. Create a table variable (virtual in-memory table) with columns that match stored procedure SP_Report resultset
  2. Declare a cursor that contains all business units and then the cursor should loop over the BU's
  3. For each BU, execute a stored procedure called SP_Report and insert the data into the table variable
  4. Finally I have to select the columns from the table variable + timestamp + BU, insert them into another table and clear the table variable.

Code:

declare @K table (BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money)
declare @FY int
declare @BU nvarchar(max)

INSERT INTO @K (BU, K, Y, A, D, YP) 
    EXEC dbo.SP_Report '2012', 'India'

SELECT * FROM @K

This code returns the result of the table variable. Now I have to use it cursor, which I don't know how to. How I can solve the same.

4 codifyed the code
source | link

I have some business unit such as India, International, US, UK. I have to:

  1. Create a table variable (virtual in-memory table) with columns that match SPROC SP_Report resultset.
  2. Declare a cursor that contains all business units and then the cursor should loop over the BU's.
  3. For each BU, execute a stored procedure called SP_Report and insert the data into the table variable.
  4. Finally I have to select the columns from the table variable + timestamp + BU, insert them into another table and clear the table variable.

    declare @K table (BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money) declare @FY int declare @BU nvarchar(max)

    INSERT INTO @K (BU,K,Y,A,D,YP) EXEC dbo.SP_Report '2012', 'India'

    SELECT * FROM @K

    Finally I have to select the columns from the table variable + timestamp + BU, insert them into another table and clear the table variable.

    declare @K table (BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money)
    declare @FY int
    declare @BU nvarchar(max)

    INSERT INTO @K
    (BU,K,Y,A,D,YP) 
    EXEC dbo.SP_Report '2012', 'India'

    SELECT * FROM @K

This code gives me the result of the table variable. Now I have to use it cursor, which I don't know how to. How I can solve the same.

I have some business unit such as India, International, US, UK. I have to:

  1. Create a table variable (virtual in-memory table) with columns that match SPROC SP_Report resultset.
  2. Declare a cursor that contains all business units and then the cursor should loop over the BU's.
  3. For each BU, execute a stored procedure called SP_Report and insert the data into the table variable.
  4. Finally I have to select the columns from the table variable + timestamp + BU, insert them into another table and clear the table variable.

    declare @K table (BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money) declare @FY int declare @BU nvarchar(max)

    INSERT INTO @K (BU,K,Y,A,D,YP) EXEC dbo.SP_Report '2012', 'India'

    SELECT * FROM @K

This code gives me the result of the table variable. Now I have to use it cursor, which I don't know how to. How I can solve the same.

I have some business unit such as India, International, US, UK. I have to:

  1. Create a table variable (virtual in-memory table) with columns that match SPROC SP_Report resultset.
  2. Declare a cursor that contains all business units and then the cursor should loop over the BU's.
  3. For each BU, execute a stored procedure called SP_Report and insert the data into the table variable.
  4. Finally I have to select the columns from the table variable + timestamp + BU, insert them into another table and clear the table variable.

    declare @K table (BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money)
    declare @FY int
    declare @BU nvarchar(max)

    INSERT INTO @K
    (BU,K,Y,A,D,YP) 
    EXEC dbo.SP_Report '2012', 'India'

    SELECT * FROM @K

This code gives me the result of the table variable. Now I have to use it cursor, which I don't know how to. How I can solve the same.

3 Formatting and grammer
source | link

I am just new to sql and exploring google from last few days but unable to get the answers of my Query Can anyone help me with

EDIT: Information I have some business unit such as India, International, US, UK

Now i have to: Create a table variable (virtual in-memory table) with columns that match SPROC SP_Report resultset. (Which i have done).

Now, I have to declare a cursor that contains all business units and then the cursor should loop over the BU's. For each BU, what i have to do is : 1)Execute SPROC, SP_Report and insert the data into the table variable. ( I did this too, but i dont know how and when to use it in Cursor.)

2) Then i have to select the columns from the table variable + timestamp + BU and insert them into the another table.

o Finally have to clear the table variable

Code: ` Declare @K table(BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money ) Declare @FY int Declare @BU nvarchar(max)

insert into @K(BU,K,Y,A,D,YP) exec [dbo].SP_Report '2012', 'India'

SELECT * FROM @K `

  1. Create a table variable (virtual in-memory table) with columns that match SPROC SP_Report resultset.
  2. Declare a cursor that contains all business units and then the cursor should loop over the BU's.
  3. For each BU, execute a stored procedure called SP_Report and insert the data into the table variable.
  4. Finally I have to select the columns from the table variable + timestamp + BU, insert them into another table and clear the table variable.

    declare @K table (BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money) declare @FY int declare @BU nvarchar(max)

    INSERT INTO @K (BU,K,Y,A,D,YP) EXEC dbo.SP_Report '2012', 'India'

    SELECT * FROM @K

This code gives me the result of the table variable.

  Now iI have to use it cursor, which iI don't know how to. How I can solve the same.

I am just new to sql and exploring google from last few days but unable to get the answers of my Query Can anyone help me with

EDIT: Information I have some business unit such as India, International, US, UK

Now i have to: Create a table variable (virtual in-memory table) with columns that match SPROC SP_Report resultset. (Which i have done).

Now, I have to declare a cursor that contains all business units and then the cursor should loop over the BU's. For each BU, what i have to do is : 1)Execute SPROC, SP_Report and insert the data into the table variable. ( I did this too, but i dont know how and when to use it in Cursor.)

2) Then i have to select the columns from the table variable + timestamp + BU and insert them into the another table.

o Finally have to clear the table variable

Code: ` Declare @K table(BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money ) Declare @FY int Declare @BU nvarchar(max)

insert into @K(BU,K,Y,A,D,YP) exec [dbo].SP_Report '2012', 'India'

SELECT * FROM @K `

This code gives me the result of the table variable.

  Now i have to use it cursor, which i don't know how to. How I can solve the same.

I have some business unit such as India, International, US, UK. I have to:

  1. Create a table variable (virtual in-memory table) with columns that match SPROC SP_Report resultset.
  2. Declare a cursor that contains all business units and then the cursor should loop over the BU's.
  3. For each BU, execute a stored procedure called SP_Report and insert the data into the table variable.
  4. Finally I have to select the columns from the table variable + timestamp + BU, insert them into another table and clear the table variable.

    declare @K table (BU nvarchar(max), K nvarchar(max),Y money, A money, D money, YP money) declare @FY int declare @BU nvarchar(max)

    INSERT INTO @K (BU,K,Y,A,D,YP) EXEC dbo.SP_Report '2012', 'India'

    SELECT * FROM @K

This code gives me the result of the table variable. Now I have to use it cursor, which I don't know how to. How I can solve the same.

2 added 766 characters in body
source | link
1
source | link