Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

Thursday, March 22, 2012

converting .dbf files to sql server 2000

Hi..

I want to convert .dbf files to sql server 2000 tables.. without using any tools. I need to create a different structure for sql server tables other than contains in the .dbf files. May be the dbf files contain only 3 columns. but i need 5 columns and some calculations to determine the values of some fields to insert into sql server table...

i need to code this using c# in asp.net.. can u help me?

thanks in advance..

Fraijo

A .dbf file is Character and Number data types but the chart below is all the different types yo need to convert that to so I don't see how you can do it without ETL(extraction transformation and loading) tool. So create a DTS package to move your data. Hope this helps.

.NET Framework Type

ADO.NET Database Type

SQL Data Type

String

Varchar

Varchar()

String

Nvarchar

Nvarchar()

String

NChar

Nchar()

String

NText

NText

String

Text

Text

Double

BigInt

Float

DateTime

DateTime

Datetime

DateTime

SmallDateTime

Smalldatetime

Int

Int

Int

Int64

BigInt

Bigint

Int16

SmallInt

smallint

Byte[]

Binary

Binary()

Byte[]

Image

Image

Byte[]

VarBinary

Varbinary()

Byte

TinyInt

Tinyint

Bool

Bit

Bit

Decimal

Decimal

Decimal

Decimal

Money

Money

Decimal

SmallMoney

SmallMoney

Float

Float

Float

Guid

UniqueIdentifier

Uniqueidentifier

Real

Real

Real

|||

Hi..

Thanks for ur reply.. but how can i access the .dbf files/tables from ASP.NET?

What are the procedures used to get the values from a .dbf file/table? the connection string. and driver and the things to connect

Hope get reply soon..

with regards

Fraijo

|||

Assuming your dbf files are for FoxPro the links below is all I have got and I cannot tell you anything about it because I have never used it. Hope this helps.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfoxgen7/html/usingaspnetwithvfp7.asp

http://forums.asp.net/853129/ShowPost.aspx

Tuesday, March 20, 2012

Converting

I have select like this:
SELECT isnull(table1.structure,'-')as structure1 FROM table1
and I get an error message:
Msg 8115, Level 16, State 6, Line 74
Arithmetic overflow error converting varchar to data type numeric.
Structure column is decimal type.
Why is this not allowed and what is the best solution?
My query in fact is much more complicated and I don't wan't to write a lot o
f corrections
Thank you,
Simon[quote from="Books Online"]
Syntax
ISNULL ( check_expression , replacement_value )
check_expression
Is the expression to be checked for NULL. check_expression can be of any
type.
replacement_value
Is the expression to be returned if check_expression is NULL.
replacement_value must have the same type as check_expresssion.
[/quote]
Your script should look like
[script]
select isnull(cast(@.d as varchar(40)),'-') as structure1 FROM table1
[/script]
Cristian Lefter, SQL Server MVP|||Because '-' is not a numeric value. Did you mean -1, or do you want to have
a dash in the output. Best practice would be to use the UI to do this, or
case table1.structure to a varchar value first. All depends on what your UI
is doing. By changing these to character strings, you might be messing up
what you are going to do with the data once you get it there.
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"simon" <simon.zupan@.stud-moderna.si> wrote in message
news:eYrqV49HFHA.3336@.TK2MSFTNGP10.phx.gbl...
I have select like this:
SELECT isnull(table1.structure,'-')as structure1 FROM table1
and I get an error message:
Msg 8115, Level 16, State 6, Line 74
Arithmetic overflow error converting varchar to data type numeric.
Structure column is decimal type.
Why is this not allowed and what is the best solution?
My query in fact is much more complicated and I don't wan't to write a lot
of corrections
Thank you,
Simon

Thursday, March 8, 2012

convert sql tables with parent-child keys relating a nested structure into a nested x

I have 5 tables in SQL Server. Each with the following design and a sample
chain of the relationships from the root (WRL - World)
UUS is the 'Code' of the first table and it is the 'Parent' value of the
second table, etc.
Parent varchar 3
Name varchar 60
Code varchar 3
WRL United States UUS <- UUS California UCA <- UCA North Coast UNC <- UNC
Sonoma County USO <- USO Russian River Valley URR
If I have 6 tables with these relationships from root to these vineyard
appellation locations, how could I convert this nested, hiearchical data
from SQL Server tables into a nested XML file? I will be using the XML
file as input for a Winforms Treeview display of this data.
Thank you! -gregDepending on the complexity of the relationships and the XML you want, look
either into FOR XML AUTO (simple but limited) or FOR XML EXPLICIT (more
complex but powerful). If you have problems, there are people here that will
be able to help you for a good bottle :-).
Also, SQL Server 2005 will have a new FOR XML PATH mode that gives you
simplicity and power at the same time...
Best regards
Michael
"Hazz" <hazz@.nospameroosonic.net> wrote in message
news:eVYdakYMFHA.2580@.TK2MSFTNGP09.phx.gbl...
>I have 5 tables in SQL Server. Each with the following design and a sample
>chain of the relationships from the root (WRL - World)
> UUS is the 'Code' of the first table and it is the 'Parent' value of the
> second table, etc.
> Parent varchar 3
> Name varchar 60
> Code varchar 3
> WRL United States UUS <- UUS California UCA <- UCA North Coast UNC <-
> UNC Sonoma County USO <- USO Russian River Valley URR
> If I have 6 tables with these relationships from root to these vineyard
> appellation locations, how could I convert this nested, hiearchical data
> from SQL Server tables into a nested XML file? I will be using the XML
> file as input for a Winforms Treeview display of this data.
> Thank you! -greg
>|||Michael,
From what I have read since I posted this about FOR XML EXPLICIT, I think it
is time for me to step into the comfort of SQL Server 2005 and give it a
test ride.Until then what I did was this. I built the Treeview after
creating one table as per
http://www.wwwcoder.com/main/parent...68/default.aspx
then converted that recursively produced treeview node structure into the
necessary nested xml per Derek Harmon's excellent C# methods which I
massaged into vb.net for this app.
I do like this idea of the bottle bartering process!! Thank you Michael for
validating what I was finding about SQL possibilities. -greg
Here is Derek's code since I can't send a link to it;
using System;
using System.IO;
using System.Windows.Forms;
using System.Xml;
// . . .
private void SaveNode( XmlElement eNodes, TreeNodeCollection tnc)
{
foreach( TreeNode n in tnc)
this.SaveNode( eNodes, n);
}
private void SaveNode( XmlElement eNodes, TreeNode n )
{
XmlDocument nodeFactory = eNodes.OwnerDocument;
XmlElement child = nodeFactory.CreateElement( "Node");
XmlAttribute text = nodeFactory.CreateAttribute( "Text");
text.Value = n.Text;
child.Attributes.Append( text);
if ( null != n.Nodes && n.Nodes.Count > 0 )
{
XmlElement grandchildren = nodeFactory.CreateElement( "Nodes");
child.AppendChild( grandchildren);
this.SaveNode( grandchildren, n.Nodes);
}
eNodes.AppendChild( child);
}
private void btnSave_Click(object sender, System.EventArgs e)
{
XmlDocument doc = new XmlDocument( );
XmlElement eDoc = doc.CreateElement( "TreeView");
if ( null != this.treeView1.Nodes && this.treeView1.Nodes.Count > 0 )
{
XmlElement eNodes = doc.CreateElement( "Nodes");
this.SaveNode( eNodes, this.treeView1.Nodes);
eDoc.AppendChild( eNodes);
}
doc.AppendChild( eDoc);
XmlTextWriter sink = new XmlTextWriter( "../../tree.xml",
System.Text.Encoding.UTF8);
try
{
doc.WriteTo( sink);
sink.Flush( );
}
finally
{
sink.Close( );
}
}
****************************************
*********************
"Michael Rys [MSFT]" <mrys@.online.microsoft.com> wrote in message
news:umgl7SdMFHA.904@.tk2msftngp13.phx.gbl...
> Depending on the complexity of the relationships and the XML you want,
> look either into FOR XML AUTO (simple but limited) or FOR XML EXPLICIT
> (more complex but powerful). If you have problems, there are people here
> that will be able to help you for a good bottle :-).
> Also, SQL Server 2005 will have a new FOR XML PATH mode that gives you
> simplicity and power at the same time...
> Best regards
> Michael
> "Hazz" <hazz@.nospameroosonic.net> wrote in message
> news:eVYdakYMFHA.2580@.TK2MSFTNGP09.phx.gbl...
>

Friday, February 24, 2012

Convert Nested Sets to Adjacency List

Hi,
Can anyone give me an example of how to convert a tree structure
stored as a nested set into an Adjacency List?
I.e
Table(Node_ID, Left, Right)
into
Table(Node_ID, Parent_ID)
I can't get my head around the sql to do it!
(im using SQLS 2000)
Thanks
AndrewHere is one way to convert nested set to adjacency list:
CREATE TABLE NestedSet (
NodeId CHAR(1) NOT NULL PRIMARY KEY,
Lf INT NOT NULL,
Rg INT NOT NULL)
INSERT INTO NestedSet (NodeId, Lf, Rg) VALUES ('A', 1, 9)
INSERT INTO NestedSet (NodeId, Lf, Rg) VALUES ('B', 2, 3)
INSERT INTO NestedSet (NodeId, Lf, Rg) VALUES ('C', 4, 7)
INSERT INTO NestedSet (NodeId, Lf, Rg) VALUES ('D', 5, 6)
CREATE TABLE AdjacencyList (
NodeId Char(1) NOT NULL PRIMARY KEY,
ParentId Char(1) NULL)
INSERT INTO AdjacencyList
SELECT A.NodeId,
B.NodeId As ParentId
FROM NestedSet A
LEFT OUTER JOIN NestedSet B
ON B.Lf = (SELECT MAX(C.Lf)
FROM NestedSet C
WHERE C.Lf < A.Lf
AND C.Rg > A.Rg)
SELECT NodeId, ParentId FROM AdjacencyList
DROP TABLE NestedSet
DROP TABLE AdjacencyList
Regards,
Plamen Ratchev
http://www.SQLStudio.com

Sunday, February 12, 2012

Convert EXISTS to JOIN or?

Hello!
I have a query I cannot find a solution to.
Structure: Nodes transferring units. One nodes table with
info. It is related to itself, so that a node can have many
sourcenodes.
.--.
|xfers|--+
`--' |
| |
| .--+--. 1.* .--.
|--+nodes|--.intervals|
`--' `--'
The relation table is xfers (transfers). Each node has an
interval of a basic unit, a lot and start/stop.
I want access to:
- all nodes
- all sourcenodes that have an intersecting interval
(i e an interval with same lot and an intersecting
interval with the targetnode)
- the first matching intersecting interval for each node
I've been testing some different things but have not gotten
a working solution. This gives the correct rows but does
not get me access to the first matching intersecting
interval (T-SQL):
*** START SQL CODE:
-- Desired rows, yet I cannot access the matching row in
the EXISTS test
SELECT
nodes.nodeid, nodes.nodename,
source_nodeid, volume
FROM nodes
LEFT OUTER JOIN xfers
ON target_nodeid = nodes.nodeid AND EXISTS
( SELECT *
FROM intervals sourceIntervals
JOIN intervals nodeIntervals
ON
nodeIntervals.lot = sourceIntervals.lot
AND dbo.Intersection( nodeIntervals.start,
nodeIntervals.stop, sourceIntervals.start,
sourceIntervals.stop ) = 1
WHERE
sourceIntervals.nodes_nodeid = xfers.source_nodeid
AND nodeIntervals.nodes_nodeid = xfers.target_nodeid
)
LEFT OUTER JOIN nodes sourceNodes
ON sourceNodes.nodeid = source_nodeid
*** END SQL CODE
Notice use of intersection function, below.
No success in remaking this as a join so far.
Here is a setup script:
*** START SQL CODE:
CREATE TABLE nodes ( nodeid INT, nodename VARCHAR(32),
PRIMARY KEY( nodeid ) )
CREATE TABLE xfers ( target_nodeid INT, source_nodeid INT,
volume INT, PRIMARY KEY( source_nodeid, target_nodeid ) )
CREATE TABLE intervals ( nodes_nodeid INT, lot VARCHAR(3),
lotcount INT, start INT, stop INT, PRIMARY KEY(
nodes_nodeid, lot, lotcount ) )
go
INSERT INTO nodes
SELECT 12, 'Run A' UNION
SELECT 25, 'Switch A B' UNION
SELECT 26, 'Continue B' UNION
SELECT 57, 'Mix'
go
INSERT INTO intervals
SELECT 12, 'A', 1, 1, 180 UNION
SELECT 25, 'A', 1, 181, 195 UNION
SELECT 25, 'B', 1, 1, 21 UNION
SELECT 26, 'B', 1, 22, 492 UNION
SELECT 57, 'A', 1, 1, 195 UNION
SELECT 57, 'B', 1, 1, 492
go
INSERT INTO xfers
SELECT 57, 12, 15 UNION
SELECT 57, 25, 3 UNION
SELECT 57, 26, 28
go
*** END SQL CODE
Intersection function:
*** START SQL CODE:
CREATE FUNCTION Intersection ( @.startA int, @.stopA int,
@.startB int, @.stopB int )
RETURNS bit
AS
BEGIN
DECLARE @.rValue bit
IF
@.startA BETWEEN @.startB AND @.stopB
OR
@.stopA BETWEEN @.startB AND @.stopB
SET @.rValue = 1
ELSE
SET @.rValue = 0
RETURN ( @.rValue )
END
go
*** END SQL CODE
//mawimawi
What do you want to return? What is an output?
I'd rewrite a little bit the function
CREATE FUNCTION Intersection ( @.startA int, @.stopA int,
@.startB int, @.stopB int )
RETURNS bit
AS
BEGIN
RETURN CASE
WHEN @.startA BETWEEN @.startB AND @.stopB THEN 1 ELSE 0 END
END
go
"mawi" <anonymous@.discussions.microsoft.com> wrote in message
news:24d101c5344c$d11c2a50$a401280a@.phx.gbl...
> Hello!
> I have a query I cannot find a solution to.
> Structure: Nodes transferring units. One nodes table with
> info. It is related to itself, so that a node can have many
> sourcenodes.
> .--.
> |xfers|--+
> `--' |
> | |
> | .--+--. 1.* .--.
> |--+nodes|--.intervals|
> `--' `--'
> The relation table is xfers (transfers). Each node has an
> interval of a basic unit, a lot and start/stop.
> I want access to:
> - all nodes
> - all sourcenodes that have an intersecting interval
> (i e an interval with same lot and an intersecting
> interval with the targetnode)
> - the first matching intersecting interval for each node
> I've been testing some different things but have not gotten
> a working solution. This gives the correct rows but does
> not get me access to the first matching intersecting
> interval (T-SQL):
> *** START SQL CODE:
> -- Desired rows, yet I cannot access the matching row in
> the EXISTS test
> SELECT
> nodes.nodeid, nodes.nodename,
> source_nodeid, volume
> FROM nodes
> LEFT OUTER JOIN xfers
> ON target_nodeid = nodes.nodeid AND EXISTS
> ( SELECT *
> FROM intervals sourceIntervals
> JOIN intervals nodeIntervals
> ON
> nodeIntervals.lot = sourceIntervals.lot
> AND dbo.Intersection( nodeIntervals.start,
> nodeIntervals.stop, sourceIntervals.start,
> sourceIntervals.stop ) = 1
> WHERE
> sourceIntervals.nodes_nodeid = xfers.source_nodeid
> AND nodeIntervals.nodes_nodeid = xfers.target_nodeid
> )
> LEFT OUTER JOIN nodes sourceNodes
> ON sourceNodes.nodeid = source_nodeid
> *** END SQL CODE
> Notice use of intersection function, below.
> No success in remaking this as a join so far.
> Here is a setup script:
> *** START SQL CODE:
> CREATE TABLE nodes ( nodeid INT, nodename VARCHAR(32),
> PRIMARY KEY( nodeid ) )
> CREATE TABLE xfers ( target_nodeid INT, source_nodeid INT,
> volume INT, PRIMARY KEY( source_nodeid, target_nodeid ) )
> CREATE TABLE intervals ( nodes_nodeid INT, lot VARCHAR(3),
> lotcount INT, start INT, stop INT, PRIMARY KEY(
> nodes_nodeid, lot, lotcount ) )
> go
> INSERT INTO nodes
> SELECT 12, 'Run A' UNION
> SELECT 25, 'Switch A B' UNION
> SELECT 26, 'Continue B' UNION
> SELECT 57, 'Mix'
> go
> INSERT INTO intervals
> SELECT 12, 'A', 1, 1, 180 UNION
> SELECT 25, 'A', 1, 181, 195 UNION
> SELECT 25, 'B', 1, 1, 21 UNION
> SELECT 26, 'B', 1, 22, 492 UNION
> SELECT 57, 'A', 1, 1, 195 UNION
> SELECT 57, 'B', 1, 1, 492
> go
> INSERT INTO xfers
> SELECT 57, 12, 15 UNION
> SELECT 57, 25, 3 UNION
> SELECT 57, 26, 28
> go
> *** END SQL CODE
> Intersection function:
> *** START SQL CODE:
> CREATE FUNCTION Intersection ( @.startA int, @.stopA int,
> @.startB int, @.stopB int )
> RETURNS bit
> AS
> BEGIN
> DECLARE @.rValue bit
> IF
> @.startA BETWEEN @.startB AND @.stopB
> OR
> @.stopA BETWEEN @.startB AND @.stopB
> SET @.rValue = 1
> ELSE
> SET @.rValue = 0
> RETURN ( @.rValue )
> END
> go
> *** END SQL CODE
> //mawi|||I haven't digested the whole thing, but this line doesn't seem right:
@.startA BETWEEN @.startB AND @.stopB
--^ and --^ @.startA / @.stopA surely?
"mawi" <anonymous@.discussions.microsoft.com> wrote in message
news:24d101c5344c$d11c2a50$a401280a@.phx.gbl...
> Hello!
> I have a query I cannot find a solution to.
> Structure: Nodes transferring units. One nodes table with
> info. It is related to itself, so that a node can have many
> sourcenodes.
> .--.
> |xfers|--+
> `--' |
> | |
> | .--+--. 1.* .--.
> |--+nodes|--.intervals|
> `--' `--'
> The relation table is xfers (transfers). Each node has an
> interval of a basic unit, a lot and start/stop.
> I want access to:
> - all nodes
> - all sourcenodes that have an intersecting interval
> (i e an interval with same lot and an intersecting
> interval with the targetnode)
> - the first matching intersecting interval for each node
> I've been testing some different things but have not gotten
> a working solution. This gives the correct rows but does
> not get me access to the first matching intersecting
> interval (T-SQL):
> *** START SQL CODE:
> -- Desired rows, yet I cannot access the matching row in
> the EXISTS test
> SELECT
> nodes.nodeid, nodes.nodename,
> source_nodeid, volume
> FROM nodes
> LEFT OUTER JOIN xfers
> ON target_nodeid = nodes.nodeid AND EXISTS
> ( SELECT *
> FROM intervals sourceIntervals
> JOIN intervals nodeIntervals
> ON
> nodeIntervals.lot = sourceIntervals.lot
> AND dbo.Intersection( nodeIntervals.start,
> nodeIntervals.stop, sourceIntervals.start,
> sourceIntervals.stop ) = 1
> WHERE
> sourceIntervals.nodes_nodeid = xfers.source_nodeid
> AND nodeIntervals.nodes_nodeid = xfers.target_nodeid
> )
> LEFT OUTER JOIN nodes sourceNodes
> ON sourceNodes.nodeid = source_nodeid
> *** END SQL CODE
> Notice use of intersection function, below.
> No success in remaking this as a join so far.
> Here is a setup script:
> *** START SQL CODE:
> CREATE TABLE nodes ( nodeid INT, nodename VARCHAR(32),
> PRIMARY KEY( nodeid ) )
> CREATE TABLE xfers ( target_nodeid INT, source_nodeid INT,
> volume INT, PRIMARY KEY( source_nodeid, target_nodeid ) )
> CREATE TABLE intervals ( nodes_nodeid INT, lot VARCHAR(3),
> lotcount INT, start INT, stop INT, PRIMARY KEY(
> nodes_nodeid, lot, lotcount ) )
> go
> INSERT INTO nodes
> SELECT 12, 'Run A' UNION
> SELECT 25, 'Switch A B' UNION
> SELECT 26, 'Continue B' UNION
> SELECT 57, 'Mix'
> go
> INSERT INTO intervals
> SELECT 12, 'A', 1, 1, 180 UNION
> SELECT 25, 'A', 1, 181, 195 UNION
> SELECT 25, 'B', 1, 1, 21 UNION
> SELECT 26, 'B', 1, 22, 492 UNION
> SELECT 57, 'A', 1, 1, 195 UNION
> SELECT 57, 'B', 1, 1, 492
> go
> INSERT INTO xfers
> SELECT 57, 12, 15 UNION
> SELECT 57, 25, 3 UNION
> SELECT 57, 26, 28
> go
> *** END SQL CODE
> Intersection function:
> *** START SQL CODE:
> CREATE FUNCTION Intersection ( @.startA int, @.stopA int,
> @.startB int, @.stopB int )
> RETURNS bit
> AS
> BEGIN
> DECLARE @.rValue bit
> IF
> @.startA BETWEEN @.startB AND @.stopB
> OR
> @.stopA BETWEEN @.startB AND @.stopB
> SET @.rValue = 1
> ELSE
> SET @.rValue = 0
> RETURN ( @.rValue )
> END
> go
> *** END SQL CODE
> //mawi|||Mercury wrote on Tue, 29 Mar 2005 23:59:16 +1200:

> I haven't digested the whole thing, but this line doesn't seem right:
> @.startA BETWEEN @.startB AND @.stopB
> --^ and --^ @.startA / @.stopA surely?
But that would result in the clause always being true.
The function appears to return a 1 if the A values are between the B values.
Dan