Showing posts with label via. Show all posts
Showing posts with label via. Show all posts

Friday, March 30, 2012

Inserting 1:M relationship data via One Stored Procedure

Hi,

Uses: SQL Server 2000, ASP.NET 1.1;

I've the following tables which has a 1:M relationship within them:

Contact(ContactID, LastName, FirstName, Address, Email, Fax)
ContactTelephone(ContactID, TelephoneNos)

I have a webform made with asp.net, and have given the user to add maximum of 3 telephone nos for a contact (Telephone Nos can be either Mobile or Land phones). So I've used Textbox's in the following way for the appropriate fields:

LastName,
FirstName,
Address,
Fax,
Email,
MobileNo,
PhoneNo1,
PhoneNo2,
PhoneNo3.

Once the submit button is pressed, I need to take all of this values and insert them in the tables via a Single Stored Procedure. I need to know could this be done and How?

Eagerly awaiting a response.

Thanks,

The best reference for this kind of thing when you truly have a 1:M relationship is Erland's web page: http://www.sommarskog.se/arrays-in-sql.html

But if you have a max of 3, then just write the proc with 3 parameters (something like):

create procedure contact$insert
(
@.LastName,
...
@.MobileNo,
@.PhoneNo1,
@.PhoneNo2,
@.PhoneNo3
)
--add your own error handling of course or add SET XACT_ABORT ON that
--will stop the tran on any error

begin tran

insert into contact (lastName, ..., MobileNo) --note, assuming contactId is an identity
values (@.lastName, ..., @.MobileNo)

declare @.newContactId int
set @.newContactId = scope_identity()

insert into contactTelephone
select @.newContactId, @.phoneNo1
where @.phoneNo1 is not null
union all
select @.newContactId, @.phoneNo2
where @.phoneNo2 is not null
union all
select @.newContactId, @.phoneNo3
where @.phoneNo3 is not null

commit tran

|||

Hi Louis,

Thanks for the Response, this cleared my mind and the problem. Thank you again!

sql

Monday, March 26, 2012

Insert Word document into image field

How can I insert a Word document into a image field in
SQL server 7 or 2000 via ASP?
Thanks
MoroBCheck out the following links:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui07312001.asp
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q258038
--
HTH,
SriSamp
Please reply to the whole group only!
"MoroB" <m.bonini@.abax.it> wrote in message
news:09b001c3a2c2$7cfff450$a601280a@.phx.gbl...
> How can I insert a Word document into a image field in
> SQL server 7 or 2000 via ASP?
> Thanks
> MoroB|||Hi,
This is what we used, takes a bit of reading, and ignore
the .net stuff but it works.
http://support.microsoft.com/default.aspx?scid=KB;EN-
US;Q194975&
>--Original Message--
>How can I insert a Word document into a image field in
>SQL server 7 or 2000 via ASP?
>Thanks
>MoroB
>.
>|||Does It work for Visual Studio or also with asp, that
it's what i need?
MoroB
>--Original Message--
>Hi,
>This is what we used, takes a bit of reading, and ignore
>the .net stuff but it works.
>http://support.microsoft.com/default.aspx?scid=KB;EN-
>US;Q194975&
>
>>--Original Message--
>>How can I insert a Word document into a image field in
>>SQL server 7 or 2000 via ASP?
>>Thanks
>>MoroB
>>.
>.
>|||They don't work with asp
>--Original Message--
>Check out the following links:
>http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/dnaskdr/html/askgui07312001.asp
>http://support.microsoft.com/default.aspx?scid=kb;EN-
US;q258038
>--
>HTH,
>SriSamp
>Please reply to the whole group only!
>"MoroB" <m.bonini@.abax.it> wrote in message
>news:09b001c3a2c2$7cfff450$a601280a@.phx.gbl...
>> How can I insert a Word document into a image field in
>> SQL server 7 or 2000 via ASP?
>> Thanks
>> MoroB
>
>.
>|||I've not personally tested them with ASP, but they work fine with VB. So
with just some modifications, they should work in ASP.
--
HTH,
SriSamp
Please reply to the whole group only!
http://www32.brinkster.com/srisamp
<anonymous@.discussions.microsoft.com> wrote in message
news:0f0501c3a2c7$7e670c20$a101280a@.phx.gbl...
> They don't work with asp
> >--Original Message--
> >Check out the following links:
> >http://msdn.microsoft.com/library/default.asp?
> url=/library/en-us/dnaskdr/html/askgui07312001.asp
> >http://support.microsoft.com/default.aspx?scid=kb;EN-
> US;q258038
> >
> >--
> >HTH,
> >SriSamp
> >Please reply to the whole group only!
> >
> >"MoroB" <m.bonini@.abax.it> wrote in message
> >news:09b001c3a2c2$7cfff450$a601280a@.phx.gbl...
> >> How can I insert a Word document into a image field in
> >> SQL server 7 or 2000 via ASP?
> >>
> >> Thanks
> >> MoroB
> >
> >
> >.
> >

Wednesday, March 21, 2012

Insert to a Linked Server possible via Service Broker?

I have configured a non-SQL linked server (via an OLE DB provider) and I wish to insert data into it via Service Broker but I am getting the following error in the SQL Server log:

The activated proc [dbo].[sp_ mytableServiceProgram] running on queue TestDB.dbo.mytableQueue output the following:'Cannot promote the transaction to a distributed transaction because there is an active save point in this transaction.'

As you see below, my strored proc. is not issuing any 'save trans' statements, so why is it not allowing me to wrap my code in a transaction? How else can I use a transaction (in order to not lose anything from the queue) and yet still be able to insert to the linked server?

CREATE PROC sp_mytableServiceProgram

AS

SET NOCOUNT ON;

DECLARE

@.XML XML,

@.MessageBody VARBINARY(MAX),

@.MessageTypeName nvarchar(256),

@.Dialog UNIQUEIDENTIFIER;

-- This procedure continues to process messages in the queue until the

-- queue is empty.

WHILE (1 = 1)

BEGIN

BEGIN TRANSACTION;

--BEGIN DISTRIBUTED TRANSACTION; --Tried this but didn't help.

-- Receive the next available message

WAITFOR (

RECEIVE TOP(1) -- just handle one message at a time

@.MessageTypeName = message_type_name,

@.MessageBody = message_body,

@.Dialog = conversation_handle

FROM mytableQueue

), TIMEOUT 2000 ;

-- If RECEIVE did not return a message, roll back the transaction

-- and break out of the while loop, exiting the procedure.

IF (@.@.ROWCOUNT = 0)

BEGIN

ROLLBACK TRANSACTION;

BREAK;

END ;

SET @.XML = CAST(@.MessageBody AS XML);

INSERT INTO LINKEDSERVER.dbname.user.mytable

SELECT tbl.rows.value('@.doc_no', 'INT') AS doc_no,

tbl.rows.value('@.queryid', 'NVARCHAR(50)') AS queryid,

tbl.rows.value('@.ar_num', 'NVARCHAR(50)') AS ar_num,

tbl.rows.value('@.status', 'NVARCHAR(20)') AS status,

tbl.rows.value('@.creationtime', 'DATETIME') AS creationtime,

tbl.rows.value('@.note', 'NVARCHAR(250)') AS note,

tbl.rows.value('@.posted', 'NCHAR(1)') AS posted,

tbl.rows.value('@.kms', 'INT') AS kms,

tbl.rows.value('@.schresid', 'NVARCHAR(50)') AS schresid,

tbl.rows.value('@.resolution_code', 'NCHAR(8)') AS resolution_code,

tbl.rows.value('@.page_count', 'INT') AS page_count,

tbl.rows.value('@.new_serial_number', 'NVARCHAR(20)') AS new_serial_number,

tbl.rows.value('@.taskresolution', 'NVARCHAR(250)') AS taskresolution

FROM @.XML.nodes('/inserted') tbl(rows);

-- If the INSERT did not insert any rows, rollback.

IF @.@.ROWCOUNT = 0

BEGIN

ROLLBACK TRANSACTION;

BREAK;

END

COMMIT TRANSACTION;

END

GO

Is the procedure runnning fine if is invoked from a user connection (e.g. using exec sp_mytableServiceProgram from a Management Studio query) but it fails when called from activation context?

Also, what OLDDB provider are you using for the linked server?

BTW, your procedure should handle the [http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog] and [http://schemas.microsoft.com/SQL/ServiceBroker/Error] message types.

HTH,
~ Remus

|||

No, I see the same error when run as myself (but with more detail):

Msg 3933, Level 16, State 1, Procedure sp_mytableServiceProgram, Line 38

Cannot promote the transaction to a distributed transaction because there is an active save point in this transaction.

Line #38 is the insert to the linked server and the OLEDB provider is set to 'Ifxoledbc' which is for an IBM Informix database server.

And yes, you are correct, I do handle the other two message types, (just removed for posting simplicity).

Is the WAITFOR...RECEIVE statement perhaps doing an implicit SAVE TRANS for each and every message that it receives?

Regards,

Ron

|||

Is the WAITFOR that creates an internal savepoint. Remove the WAITFOR and it should work, using a plain RECEIVE. It does work for me, using an SQLNCLI linked server.

HTH,
~ Remus

|||

Right, I was able to see the same thing, removing WAITFOR allowed the insert to the linked server to go through.

But I wonder what are the repercussions to not using WAITFOR are?

Thanks,

Ron

|||

WAITFOR in activated procedures has the purpose of lingering the proedure around for a few seconds when he queue is empty, in hope another message comes anew. This avoids the situation when the rate of incoming messages is just slow enough to keep activating the procedure immedeatly after it just finished.

You should be fine, the benefits of WAITFOR show up only at one particular rate of incomming messages and the gains offered by it are not earth shatering in the first place anyway...

HTH,
~ Remus

|||Excellent, thank you.sql

Wednesday, March 7, 2012

Insert records in multiple tables via store proc

Any help will be appreacited
I need to insert records into multiple tables via store proc. I wrote a query statement that does that, but I need to carry one value to the next piece of the script, which is easy via query analizer, but I do not know how to pass that value to the next step in the store proc. Please see the query I am using to give me some light. The case sample is 9731285 and needs to be carry out to each step in the store proc. Thank you!
DECLARE @.Casenumber as char(20
SET @.CASENUMBER = '9731285
INSERT INTO tblCaseDat
(CaseNumber, DisplayCaseNumber
VALUES (@.CASENUMBER, (left(@.casenumber, 2))+'-'+rtrim(Right(@.casenumber,18))
G
declare @.casenumber char(20
select @.casenumber = '9731285
INSERT INTO tblname (longname
values (@.casenumber+' '+ 'Debtor1'
g
declare @.casenumber char (20
select @.casenumber = '9731285
INSERT INTO tblCasename (caseid, NameID, NameTypeID
(select caseid, (Select NameI
from tblnam
where longname =(@.casenumber+' '+ 'Debtor1')), '5
from tblcasedat
where casenumber = @.casenumber
G
declare @.casenumber char(20
select @.casenumber = '9731285
INSERT INTO tblname (longname
values (@.casenumber+' '+ 'Debtor2'
g
declare @.casenumber char (20
select @.casenumber = '9731285
INSERT INTO tblCasename (caseid, NameID, NameTypeID
(select caseid, (Select NameI
from tblnam
where longname =(@.casenumber+' '+ 'Debtor2')), '6
from tblcasedat
where casenumber = @.casenumber
Gthe batch separator (GO) resets any variable declarations.
hence, if you remove the 'GO'
remove the additional DECLARE / SET CaseNumber,
you can execution the entire set of statments as one
batch, which can be put into a stored proc,
also, an explicit BEGIN TRAN , COMMIT TRAN around the
entire set of inserts statements is probably warranted
>--Original Message--
>Any help will be appreacited.
>I need to insert records into multiple tables via store
proc. I wrote a query statement that does that, but I need
to carry one value to the next piece of the script, which
is easy via query analizer, but I do not know how to pass
that value to the next step in the store proc. Please see
the query I am using to give me some light. The case
sample is 9731285 and needs to be carry out to each step
in the store proc. Thank you!!
>DECLARE @.Casenumber as char(20)
>SET @.CASENUMBER = '9731285'
>INSERT INTO tblCaseData
> (CaseNumber, DisplayCaseNumber)
>VALUES (@.CASENUMBER, (left(@.casenumber, 2))+'-'+rtrim
(Right(@.casenumber,18)))
>GO
>declare @.casenumber char(20)
>select @.casenumber = '9731285'
>INSERT INTO tblname (longname)
> values (@.casenumber+' '+ 'Debtor1')
>go
>declare @.casenumber char (20)
>select @.casenumber = '9731285'
>INSERT INTO tblCasename (caseid, NameID, NameTypeID)
> (select caseid, (Select NameID
> from tblname
> where longname =(@.casenumber+' '+ 'Debtor1')), '5'
> from tblcasedata
> where casenumber = @.casenumber)
>GO
>declare @.casenumber char(20)
>select @.casenumber = '9731285'
>INSERT INTO tblname (longname)
> values (@.casenumber+' '+ 'Debtor2')
>go
>declare @.casenumber char (20)
>select @.casenumber = '9731285'
>INSERT INTO tblCasename (caseid, NameID, NameTypeID)
> (select caseid, (Select NameID
> from tblname
> where longname =(@.casenumber+' '+ 'Debtor2')), '6'
> from tblcasedata
> where casenumber = @.casenumber)
>GO
>.
>

Sunday, February 19, 2012

Insert Oracle Linked Server timestamp error...

I'm trying to insert into an Oracle table, setup via a linked server.
Everything works, but I receive an error during the insert, the
statement and error are below:
INSERT INTO ORALINKSRV..FIN.FILE_XFER_STATUS_DETAIL
(FILE_SEQ_ID,FILE_RETURN_CD,OFFICE_DEPT_
ID,FILE_NM,
FILE_PROC_DTTM FILE_SUFFIX_ID)
Select FILE_SEQ_ID,FILE_RETURN_CD,OFFICE_DEPT_I
D,FILE_NM,
FILE_PROC_DTTM,FILE_SUFFIX_ID
From Temp_FIN_Detail
ERROR:
Server: Msg 7354, Level 16, State 1, Line 1
OLE DB provider 'MSDAORA' supplied invalid metadata for column
'FILE_PROC_DTTM'. The data type is not supported.
OLE DB error trace [Non-interface error: Column 'FILE_PROC_DTTM'
(ordinal 5) of object '"FIN"."FILE_XFER_STATUS_DETAIL"' reported an
unsupported value for DBTYPE of 13].
We've updated to the latest Oracle drivers on the server. We've
switched between the Oracle and MS OleDB Providers.
Any work arounds appreciated...
Thanks
bobAdditional information.
This is Oracle 9.203.
Oracle introduced a new data type timestamp, this data type does not
seem to be updateable or insert via SQL Server linked server.
I'd appreciate if anyone else could test and confirm this. We've
contacted MS Support and they weren't very helpful, indicating we were
the only ones who have reported a problem, and that is is most likely
an Oracle problem.
I'm just looking for some guidance so we can establish a standard to
not use the Oracle time stamp data type on tables that require data to
be transferred back and forth between SQL Server and Oracle.
Thanks
bob|||Try using Openquery and wrapping the value in to_timestamp.
You should also check your nls timestamp format on the
Oracle server.
-Sue
On 28 May 2004 12:34:05 -0700, bob@.lifeasbob.com (Bob
Horkay) wrote:

>Additional information.
>This is Oracle 9.203.
>Oracle introduced a new data type timestamp, this data type does not
>seem to be updateable or insert via SQL Server linked server.
>I'd appreciate if anyone else could test and confirm this. We've
>contacted MS Support and they weren't very helpful, indicating we were
>the only ones who have reported a problem, and that is is most likely
>an Oracle problem.
>I'm just looking for some guidance so we can establish a standard to
>not use the Oracle time stamp data type on tables that require data to
>be transferred back and forth between SQL Server and Oracle.
>Thanks
>bob|||Sue,
The query can be made to work for openquery with a to_char() statement,
unfortunately this does not work for Inserts.
I finally did receive a response from Microsoft support, the timestamp data
type is not supported, there is no plan to support it. They suggested using
the .net managed providers for Oracle, which of course can not be used for
linked servers.
They referenced several kb articles about data types supported and not
supported in Oracle, but basically the timestamp, clobs and blobs were out
( i expected the blobs but was surprised by the timestamp).
Anyway at least I know Microsofts position on it's ole db provider, they
support it, but have no plans to enhance it, watch thos data types
introduced from Oracle 8 on...
Bob
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:04snb01147cfcpn394k2ufrrv9jsr953u9@.
4ax.com...
> Try using Openquery and wrapping the value in to_timestamp.
> You should also check your nls timestamp format on the
> Oracle server.
> -Sue
> On 28 May 2004 12:34:05 -0700, bob@.lifeasbob.com (Bob
> Horkay) wrote:
>
>

Insert Oracle Linked Server timestamp error...

I'm trying to insert into an Oracle table, setup via a linked server.
Everything works, but I receive an error during the insert, the
statement and error are below:
INSERT INTO ORALINKSRV..FIN.FILE_XFER_STATUS_DETAIL
(FILE_SEQ_ID,FILE_RETURN_CD,OFFICE_DEPT_ID,FILE_NM ,
FILE_PROC_DTTM FILE_SUFFIX_ID)
Select FILE_SEQ_ID,FILE_RETURN_CD,OFFICE_DEPT_ID,FILE_NM,
FILE_PROC_DTTM,FILE_SUFFIX_ID
From Temp_FIN_Detail
ERROR:
Server: Msg 7354, Level 16, State 1, Line 1
OLE DB provider 'MSDAORA' supplied invalid metadata for column
'FILE_PROC_DTTM'. The data type is not supported.
OLE DB error trace [Non-interface error: Column 'FILE_PROC_DTTM'
(ordinal 5) of object '"FIN"."FILE_XFER_STATUS_DETAIL"' reported an
unsupported value for DBTYPE of 13].
We've updated to the latest Oracle drivers on the server. We've
switched between the Oracle and MS OleDB Providers.
Any work arounds appreciated...
Thanks
bob
Additional information.
This is Oracle 9.203.
Oracle introduced a new data type timestamp, this data type does not
seem to be updateable or insert via SQL Server linked server.
I'd appreciate if anyone else could test and confirm this. We've
contacted MS Support and they weren't very helpful, indicating we were
the only ones who have reported a problem, and that is is most likely
an Oracle problem.
I'm just looking for some guidance so we can establish a standard to
not use the Oracle time stamp data type on tables that require data to
be transferred back and forth between SQL Server and Oracle.
Thanks
bob
|||Try using Openquery and wrapping the value in to_timestamp.
You should also check your nls timestamp format on the
Oracle server.
-Sue
On 28 May 2004 12:34:05 -0700, bob@.lifeasbob.com (Bob
Horkay) wrote:

>Additional information.
>This is Oracle 9.203.
>Oracle introduced a new data type timestamp, this data type does not
>seem to be updateable or insert via SQL Server linked server.
>I'd appreciate if anyone else could test and confirm this. We've
>contacted MS Support and they weren't very helpful, indicating we were
>the only ones who have reported a problem, and that is is most likely
>an Oracle problem.
>I'm just looking for some guidance so we can establish a standard to
>not use the Oracle time stamp data type on tables that require data to
>be transferred back and forth between SQL Server and Oracle.
>Thanks
>bob
|||Sue,
The query can be made to work for openquery with a to_char() statement,
unfortunately this does not work for Inserts.
I finally did receive a response from Microsoft support, the timestamp data
type is not supported, there is no plan to support it. They suggested using
the .net managed providers for Oracle, which of course can not be used for
linked servers.
They referenced several kb articles about data types supported and not
supported in Oracle, but basically the timestamp, clobs and blobs were out
( i expected the blobs but was surprised by the timestamp).
Anyway at least I know Microsofts position on it's ole db provider, they
support it, but have no plans to enhance it, watch thos data types
introduced from Oracle 8 on...
Bob
"Sue Hoegemeier" <Sue_H@.nomail.please> wrote in message
news:04snb01147cfcpn394k2ufrrv9jsr953u9@.4ax.com...
> Try using Openquery and wrapping the value in to_timestamp.
> You should also check your nls timestamp format on the
> Oracle server.
> -Sue
> On 28 May 2004 12:34:05 -0700, bob@.lifeasbob.com (Bob
> Horkay) wrote:
>