Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 24th, 2007, 04:26 AM
Authorized User
 
Join Date: Jul 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Doubt on using cursor

Hi,
   I have an excel sheet which gives me the resource details(the number of resource assigned for a project). Using "Import and export data" wizard, i exported to sql server.
   I have got two more tables, one is project table which has the project details and another is status table which has the weekly status regarding a project.
Example: Resource table:
         Projid projname resource
         ------------------------------
           1 abc 23
           2 mno 45
Project table:
        PId Projid Projname Prdetails.............
        ------------------------------
        78 1 abc sample1
        79 1 abc sample2
        80 2 mno test1
status table:
       Id PId date resource
       ---------------------------------
        56 78 1/1/2007 23
        57 79 1/1/2007 23
        58 80 1/1/2007 45
My problem, resouce table has only projid and projname for which there are more than one entries in Project table(because projid, projname and prdetails form the composite primary key).
For the given projid and projname I have to get the PId from Project table and insert new records in status table with the PId and resource data given by resource table.
Since @@fetch_status is a global variable. I cannot use cursor for looping through the records generated by resource table and project table to insert a new record in status table.
Can any one help me how to solve this problem.

 
Old October 24th, 2007, 04:59 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

INSERT INTO Status (PId, date, resource)
SELECT Project.PId, '" & [date value] & "', Resource.resource FROM Project INNER JOIN Resource ON Resource.Projid = Project.Projid

You don't really need the projname column in the project table. You can always access that data from the Resource table and it will normalize your database. No sense in having the same data in two places.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Magnetic Cursor - Target Area Cursor? gcarcass .NET Framework 2.0 1 May 5th, 2008 07:20 AM
doubt somavenki .NET Framework 2.0 2 February 3rd, 2008 11:29 AM
doubt sampathk Visual Basic 2005 Basics 1 November 28th, 2006 02:45 PM
doubt! kk_katepally ASP.NET 1.0 and 1.1 Basics 1 February 7th, 2006 01:58 PM
doubt naveen J2EE 1 April 6th, 2004 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.