Showing posts with label auto. Show all posts
Showing posts with label auto. Show all posts

Monday, March 26, 2012

how can I push xml data back to table?

Hi, I have a xml string that reveived from select ... for xml auto in sql
server 2005, now how can I push these xml data back to another sql server
database table? Thx a lot.
Risen
Hello Risen,
R> Hi, I have a xml string that reveived from select ... for xml auto
R> in sql server 2005, now how can I push these xml data back to another
R> sql server database table? Thx a lot.
In SQL 2000 or 2005, look into OPENXML.
In 2005, you also have the option of using the XML datatype and the nodes
function or using SSIS or writing your own SQLCLR parser.
Lots of ways to skin that Cat. The Cat won't like any of them. :X
Thanks,
Kent Tegels
http://staff.develop.com/ktegels/
|||Thanks : )
"Kent Tegels" <ktegels@.develop.com>
?:b87ad74ba118c8c096c4c89b30@.news.microsoft.c om...
> Hello Risen,
> R> Hi, I have a xml string that reveived from select ... for xml auto
> R> in sql server 2005, now how can I push these xml data back to another
> R> sql server database table? Thx a lot.
> In SQL 2000 or 2005, look into OPENXML.
> In 2005, you also have the option of using the XML datatype and the nodes
> function or using SSIS or writing your own SQLCLR parser.
> Lots of ways to skin that Cat. The Cat won't like any of them. :X
> Thanks,
> Kent Tegels
> http://staff.develop.com/ktegels/
>
>
|||You can also use Xml Bulkload functionality.
See more on this :http://msdn2.microsoft.com/en-us/library/ms171993.aspx
Regards,
Monica Frintu
"Risen" wrote:

> Thanks : )
>
> "Kent Tegels" <ktegels@.develop.com>
> ?:b87ad74ba118c8c096c4c89b30@.news.microsoft.c om...
>
>

how can I push xml data back to table?

Hi, I have a xml string that reveived from select ... for xml auto in sql
server 2005, now how can I push these xml data back to another sql server
database table? Thx a lot.
RisenHello Risen,
R> Hi, I have a xml string that reveived from select ... for xml auto
R> in sql server 2005, now how can I push these xml data back to another
R> sql server database table? Thx a lot.
In SQL 2000 or 2005, look into OPENXML.
In 2005, you also have the option of using the XML datatype and the nodes
function or using SSIS or writing your own SQLCLR parser.
Lots of ways to skin that Cat. The Cat won't like any of them. :X
Thanks,
Kent Tegels
http://staff.develop.com/ktegels/|||Thanks : )
"Kent Tegels" <ktegels@.develop.com>
':b87ad74ba118c8c096c4c89b30@.news.microsoft.com...
> Hello Risen,
> R> Hi, I have a xml string that reveived from select ... for xml auto
> R> in sql server 2005, now how can I push these xml data back to another
> R> sql server database table? Thx a lot.
> In SQL 2000 or 2005, look into OPENXML.
> In 2005, you also have the option of using the XML datatype and the nodes
> function or using SSIS or writing your own SQLCLR parser.
> Lots of ways to skin that Cat. The Cat won't like any of them. :X
> Thanks,
> Kent Tegels
> http://staff.develop.com/ktegels/
>
>|||You can also use Xml Bulkload functionality.
See more on this :http://msdn2.microsoft.com/en-us/library/ms171993.aspx
Regards,
--
Monica Frintu
"Risen" wrote:

> Thanks : )
>
> "Kent Tegels" <ktegels@.develop.com>
> ':b87ad74ba118c8c096c4c89b30@.news.microsoft.com...
>
>

Friday, March 9, 2012

How can I INSERT w/Constraints in other tables?

Three tables (all new, no data) will receive data from dBase and be
transposed into them...All three have auto generated IDENTITY columns
and pk and fk constraints. Can someone provide me with an
understandible sample?
Thanks,
TrintThis example may help. Assuming your tables look like this:

CREATE TABLE Foo (foo_id INTEGER IDENTITY PRIMARY KEY, foo_key
VARCHAR(10) NOT NULL UNIQUE)

CREATE TABLE Bar (bar_id INTEGER IDENTITY PRIMARY KEY, bar_key
VARCHAR(10) NOT NULL UNIQUE, foo_id INTEGER NOT NULL REFERENCES Foo
(foo_id))

And assuming you have a similar source structure from dBase, here are
the INSERTs:

INSERT INTO Foo (foo_key)
SELECT DISTINCT foo_key
FROM Foo_source

INSERT INTO Bar (bar_key, foo_id)
SELECT DISTINCT B.bar_key, F2.foo_id
FROM Bar_source AS B
JOIN Foo_source AS F
ON B.foo_id = F.foo_id
JOIN Foo AS F2
ON F.foo_key = F2.foo_key

For this to work you do of course need the alternate key ("foo_key" in
this case). That shouldn't be a problem. IDENTITY should never be the
only key of a table.

--
David Portas
SQL Server MVP
--|||David,
Here are the two tables...can you help in using the example with them?::

CREATE TABLE [tblTravelDetailMember] (
[TravelDetailUplineId] [int] NOT NULL ,
[TravelDetailId] [int] NOT NULL ,
[TravelDetailMemberTypeId] [int] NOT NULL ,
[memberId] [bigint] NOT NULL ,
[rankId] [int] NOT NULL ,
[CreatedDateTime] [datetime] NOT NULL ,
[Operator] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
CONSTRAINT [PK_tblTravelDetailMember] PRIMARY KEY CLUSTERED
(
[TravelDetailUplineId]
) ON [PRIMARY] ,
CONSTRAINT [FK_tblTravelDetailMember_tblTravelDetail] FOREIGN KEY
(
[TravelDetailId]
) REFERENCES [tblTravelDetail] (
[TravelDetailId]
),
CONSTRAINT [FK_tblTravelDetailMember_tblTravelDetailMemberType ] FOREIGN
KEY
(
[TravelDetailMemberTypeId]
) REFERENCES [tblTravelDetailMemberType] (
[TravelDetailMemberTypeId]
)
) ON [PRIMARY]
GO

------

CREATE TABLE [tblTravelDetailMemberType] (
[TravelDetailMemberTypeId] [int] NOT NULL ,
[Description] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[CreatedDateTime] [datetime] NOT NULL ,
[Operator] [nvarchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
CONSTRAINT [PK_tblTravelDetailMemberType] PRIMARY KEY CLUSTERED
(
[TravelDetailMemberTypeId]
) ON [PRIMARY]
) ON [PRIMARY]
GO

I get this error with this code:
string strSQL2 = "INSERT INTO tblTravelDetailMember(memberId, " +
" TravelDetailUplineId, " +
" rankId, " +
" TravelDetailId, " +
" CreatedDateTime, " +
" Operator) " +
"VALUES ('" + insertString2 + "', " +
" '" + insertString3 + "', " +
" '" + insertString4 + "', " +
" '" + insertString5 + "', " +
" '" + insertString6 + "', " +
" '" + insertString7 + "')";

Thanks,
Trint

Net programmer
trinity.smith@.gmail.com

*** Sent via Developersdex http://www.developersdex.com ***|||You didn't specify what error message you are getting. You didn't
include the alternate keys or the IDENTITY properties that you said you
had. The only obvious problem with your INSERT is that you've missed
out one of the columns ("TravelDetailMemberTypeId").

Put the INSERT in a stored procedure rather than construct a SQL string
in your app. That way you can test and check the code more easily.

If you only want to insert rows one at a time then you should be able
to make use of the SCOPE_IDENTITY() function to do this. See Books
Online for details. I was assuming you would load all the data with one
INSERT per table.

--
David Portas
SQL Server MVP
--

How can i insert a curreny formated column

Hi i have made a column that is called carprice. Instead of just typing in £500 i want to be able to put in 500 and then have sql auto format it to £500 in the column. In other words just put the £ price infront. Is there a way of doing this thanks.A currency value should be left as a number without any symbols. The client side code should be the one formatting the value with the appropriate currency symbol. DotNet has support for this type of thing for client side formatting.|||I agree, storing as a number is the best design. Later when you need to use that data in a calculation, you dont have to try and parse it and deal with invalid entries. But the downside to just having a number is that you have no idea what currency that number is in. So if your app has any possibilities of ever going global, you might consider having a second field to track the currency. You could have a dropdown that lists all the currencies you support. You could then case on the currency to do the formatting of the output of the value you stored as a number.