Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 January 25th, 2007, 10:47 PM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default spliting database in record level

how i can split up the database in record level like following ---

id name now ===> want so show my data like this
1 a
2 b 1 a
3 c 8 h
4 d 2 b
5 e 7 g
6 f 3 c
7 g 6 f
8 h 4 d
                           5 e

 
Old January 26th, 2007, 12:07 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Ok... here's the answer... but you have to tell me why you needed to do this...

Code:
--===== Setup the test data
 CREATE TABLE #MyHead
        (
        ID INT,
        Name VARCHAR(10)
        )

 INSERT INTO #MyHead 
        (ID,Name)
 SELECT 1,'a' UNION ALL                       
 SELECT 2,'b' UNION ALL       
 SELECT 3,'c' UNION ALL       
 SELECT 4,'d' UNION ALL      
 SELECT 5,'e' UNION ALL      
 SELECT 6,'f' UNION ALL       
 SELECT 7,'g' UNION ALL      
 SELECT 8,'h'

--===== Demo the solution
DECLARE @MaxPoint INT
DECLARE @HalfPoint INT

 SELECT @MaxPoint  = MAX(ID)+1, 
        @HalfPoint = MAX(ID)/2
   FROM #MyHead

 SELECT d.ID,d.Name
   FROM
        (
         SELECT t1.ID AS ThisPoint, t1.*
           FROM #MyHead t1
          WHERE t1.ID <= @HalfPoint
          UNION ALL
         SELECT @MaxPoint-t2.ID AS ThisPoint, t2.*
           FROM #MyHead t2
          WHERE t2.ID > @HalfPoint
        ) d
  ORDER BY d.ThisPoint


--Jeff Moden
 
Old January 27th, 2007, 04:39 AM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi jeff,
thanx for your prompt reply. but when i was trying code its showing data other then the requirment--its code data showing like this --

1 a
8 h upto now ok but next it should be 2 but output is
7 g
2 b this line should be at the place of 7
3 c
6 f
5 e
4 d

 
Old January 28th, 2007, 12:43 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Applogies... left off part of the Order By when I did the cut and paste...

--===== Setup the test data
 CREATE TABLE #MyHead
        (
        ID INT,
        Name VARCHAR(10)
        )

 INSERT INTO #MyHead
        (ID,Name)
 SELECT 1,'a' UNION ALL
 SELECT 2,'b' UNION ALL
 SELECT 3,'c' UNION ALL
 SELECT 4,'d' UNION ALL
 SELECT 5,'e' UNION ALL
 SELECT 6,'f' UNION ALL
 SELECT 7,'g' UNION ALL
 SELECT 8,'h'

--===== Demo the solution
DECLARE @MaxPoint INT
DECLARE @HalfPoint INT

 SELECT @MaxPoint = MAX(ID)+1,
        @HalfPoint = MAX(ID)/2
   FROM #MyHead

 SELECT d.ID,d.Name
   FROM
        (
         SELECT t1.ID AS ThisPoint, t1.*
           FROM #MyHead t1
          WHERE t1.ID <= @HalfPoint
          UNION ALL
         SELECT @MaxPoint-t2.ID AS ThisPoint, t2.*
           FROM #MyHead t2
          WHERE t2.ID > @HalfPoint
        ) d
 ORDER BY d.ThisPoint,d.ID



--Jeff Moden
 
Old January 29th, 2007, 10:40 PM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thank you so much jeff. its a great help.
Another problem --

how can i import DBF to SQL. no way seems like i can make it, for sure it is beginner like me. not for you jeff

thanks jeff

 
Old January 30th, 2007, 07:32 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

DTS in SQL Server has several dBase import filters. Go to Enterprise Manager and select [Tools][Data Transformation Services] and then follow your nose.

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Spliting a record Tachyophan Access VBA 3 October 25th, 2006 03:10 AM
Spliting a data table Hennie Access 7 July 21st, 2006 06:45 AM
Linked Comboboxes at the database level? howardb1 Access VBA 7 April 27th, 2006 04:17 AM
Updating the record in database lwebzem ASP.NET 1.0 and 1.1 Basics 4 March 8th, 2006 09:40 AM
Clearing record level locks IronStar MySQL 1 July 5th, 2005 08:58 PM





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