 |
| 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
|
|
|
|

January 25th, 2007, 10:47 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 26th, 2007, 12:07 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
|
|
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
|
|

January 27th, 2007, 04:39 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 28th, 2007, 12:43 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
|
|
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
|
|

January 29th, 2007, 10:40 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

January 30th, 2007, 07:32 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
|
|
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
|
|
 |