Apparently I could not insert a text field to another table from INSERTED in
a trigger.
It seems the following is working, do you see any problem joining INSERTED
to the mySrcTable which is the table that has this trigger
INSERT INTO myRemoteDatabase.dbo.myDestTable (myTrID,myFirstName,myBigText)
SELECT i.myTrID, i.myFirstName, p.myBigText
FROM INSERTED i INNER JOIN mySrcTable p ON i.myTrID = p.myTrID
WHERE (i.myTrType = 'In')
Thanks,Hi Jim
From Books Online "Create Trigger" topic
In a DELETE, INSERT, or UPDATE trigger, SQL Server does not allow text,
ntext, or image column references in the inserted and deleted tables if the
compatibility level is equal to 70. The text, ntext, and image values in the
inserted and deleted tables cannot be accessed. To retrieve the new value in
either an INSERT or UPDATE trigger, join the inserted table with the origina
l
update table. When the compatibility level is 65 or lower, null values are
returned for inserted or deleted text, ntext, or image columns that allow
null values; zero-length strings are returned if the columns are not
nullable.
If the compatibility level is 80 or higher, SQL Server allows the update of
text, ntext, or image columns through the INSTEAD OF trigger on tables or
views.
If you use an instead of trigger your logic will have to be different as
mentioned in one of your earlier posts. If you are not going to hold more
than 8000 characters in this column change it to varchar.
John
"JIM.H." wrote:
> Apparently I could not insert a text field to another table from INSERTED
in
> a trigger.
> It seems the following is working, do you see any problem joining INSERTED
> to the mySrcTable which is the table that has this trigger
> INSERT INTO myRemoteDatabase.dbo.myDestTable (myTrID,myFirstName,myBigT
ext)
> SELECT i.myTrID, i.myFirstName, p.myBigText
> FROM INSERTED i INNER JOIN mySrcTable p ON i.myTrID = p.myTrID
> WHERE (i.myTrType = 'In')
> Thanks,
>|||Thanks John.
"John Bell" wrote:
[vbcol=seagreen]
> Hi Jim
> From Books Online "Create Trigger" topic
> In a DELETE, INSERT, or UPDATE trigger, SQL Server does not allow text,
> ntext, or image column references in the inserted and deleted tables if th
e
> compatibility level is equal to 70. The text, ntext, and image values in t
he
> inserted and deleted tables cannot be accessed. To retrieve the new value
in
> either an INSERT or UPDATE trigger, join the inserted table with the origi
nal
> update table. When the compatibility level is 65 or lower, null values are
> returned for inserted or deleted text, ntext, or image columns that allow
> null values; zero-length strings are returned if the columns are not
> nullable.
> If the compatibility level is 80 or higher, SQL Server allows the update o
f
> text, ntext, or image columns through the INSTEAD OF trigger on tables or
> views.
> If you use an instead of trigger your logic will have to be different as
> mentioned in one of your earlier posts. If you are not going to hold more
> than 8000 characters in this column change it to varchar.
> John
> "JIM.H." wrote:
>
Wednesday, March 7, 2012
q; past and future date
How should I find the dates for 3 days past and 5 days future. Such as
TodayDate-3 and TodayDate+5 base in the date only, discarding the time?One method:
SELECT SomeData
FROM dbo.MyTable
WHERE
MyDate >= DATEADD(dd, -3, DATEDIFF(dd, 0, GETDATE())) AND
MyDate < DATEADD(dd, 6, DATEDIFF(dd, 0, GETDATE()))
Hope this helps.
Dan Guzman
SQL Server MVP
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:0A94FA08-3A91-4F0C-9117-0721F782E7E3@.microsoft.com...
> How should I find the dates for 3 days past and 5 days future. Such as
> TodayDate-3 and TodayDate+5 base in the date only, discarding the time?
TodayDate-3 and TodayDate+5 base in the date only, discarding the time?One method:
SELECT SomeData
FROM dbo.MyTable
WHERE
MyDate >= DATEADD(dd, -3, DATEDIFF(dd, 0, GETDATE())) AND
MyDate < DATEADD(dd, 6, DATEDIFF(dd, 0, GETDATE()))
Hope this helps.
Dan Guzman
SQL Server MVP
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:0A94FA08-3A91-4F0C-9117-0721F782E7E3@.microsoft.com...
> How should I find the dates for 3 days past and 5 days future. Such as
> TodayDate-3 and TodayDate+5 base in the date only, discarding the time?
Labels:
astodaydate-3,
base,
database,
date,
dates,
discarding,
future,
microsoft,
mysql,
oracle,
server,
sql,
todaydate5
q; past and future date
How should I find the dates for 3 days past and 5 days future. Such as
TodayDate-3 and TodayDate+5 base in the date only, discarding the time?One method:
SELECT SomeData
FROM dbo.MyTable
WHERE
MyDate >= DATEADD(dd, -3, DATEDIFF(dd, 0, GETDATE())) AND
MyDate < DATEADD(dd, 6, DATEDIFF(dd, 0, GETDATE()))
--
Hope this helps.
Dan Guzman
SQL Server MVP
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:0A94FA08-3A91-4F0C-9117-0721F782E7E3@.microsoft.com...
> How should I find the dates for 3 days past and 5 days future. Such as
> TodayDate-3 and TodayDate+5 base in the date only, discarding the time?
TodayDate-3 and TodayDate+5 base in the date only, discarding the time?One method:
SELECT SomeData
FROM dbo.MyTable
WHERE
MyDate >= DATEADD(dd, -3, DATEDIFF(dd, 0, GETDATE())) AND
MyDate < DATEADD(dd, 6, DATEDIFF(dd, 0, GETDATE()))
--
Hope this helps.
Dan Guzman
SQL Server MVP
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:0A94FA08-3A91-4F0C-9117-0721F782E7E3@.microsoft.com...
> How should I find the dates for 3 days past and 5 days future. Such as
> TodayDate-3 and TodayDate+5 base in the date only, discarding the time?
Labels:
base,
database,
date,
dates,
discarding,
future,
microsoft,
mysql,
oracle,
server,
sql,
todaydate-3,
todaydate5
q; output to a text file
Is it possible to send the output of a query to a text file in a stored
procedure? When I run stored procedure in Query Analyzer I am able to do that
and I am wondering if this is possible in a automated way?Not directly. But indirectly, you can use xp_cmdshell and BCP or OSQL. Note that the file is created
by the database server. If you are on 2005, you can also call an Assembly, if that suits you better.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:33A04A73-5811-4479-A181-67A3F999C770@.microsoft.com...
> Is it possible to send the output of a query to a text file in a stored
> procedure? When I run stored procedure in Query Analyzer I am able to do that
> and I am wondering if this is possible in a automated way?|||In order to output to a file, you would have to use ( xp_cmdshell and OSQL )
OR bcp.
Check [ BCP Utility ] or [OSQL ] in Book Online
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:33A04A73-5811-4479-A181-67A3F999C770@.microsoft.com...
> Is it possible to send the output of a query to a text file in a stored
> procedure? When I run stored procedure in Query Analyzer I am able to do
> that
> and I am wondering if this is possible in a automated way?
procedure? When I run stored procedure in Query Analyzer I am able to do that
and I am wondering if this is possible in a automated way?Not directly. But indirectly, you can use xp_cmdshell and BCP or OSQL. Note that the file is created
by the database server. If you are on 2005, you can also call an Assembly, if that suits you better.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:33A04A73-5811-4479-A181-67A3F999C770@.microsoft.com...
> Is it possible to send the output of a query to a text file in a stored
> procedure? When I run stored procedure in Query Analyzer I am able to do that
> and I am wondering if this is possible in a automated way?|||In order to output to a file, you would have to use ( xp_cmdshell and OSQL )
OR bcp.
Check [ BCP Utility ] or [OSQL ] in Book Online
--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:33A04A73-5811-4479-A181-67A3F999C770@.microsoft.com...
> Is it possible to send the output of a query to a text file in a stored
> procedure? When I run stored procedure in Query Analyzer I am able to do
> that
> and I am wondering if this is possible in a automated way?
q; output to a text file
Is it possible to send the output of a query to a text file in a stored
procedure? When I run stored procedure in Query Analyzer I am able to do tha
t
and I am wondering if this is possible in a automated way?Not directly. But indirectly, you can use xp_cmdshell and BCP or OSQL. Note
that the file is created
by the database server. If you are on 2005, you can also call an Assembly, i
f that suits you better.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:33A04A73-5811-4479-A181-67A3F999C770@.microsoft.com...
> Is it possible to send the output of a query to a text file in a stored
> procedure? When I run stored procedure in Query Analyzer I am able to do t
hat
> and I am wondering if this is possible in a automated way?|||In order to output to a file, you would have to use ( xp_cmdshell and OSQL )
OR bcp.
Check [ BCP Utility ] or [OSQL ] in Book Online
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:33A04A73-5811-4479-A181-67A3F999C770@.microsoft.com...
> Is it possible to send the output of a query to a text file in a stored
> procedure? When I run stored procedure in Query Analyzer I am able to do
> that
> and I am wondering if this is possible in a automated way?
procedure? When I run stored procedure in Query Analyzer I am able to do tha
t
and I am wondering if this is possible in a automated way?Not directly. But indirectly, you can use xp_cmdshell and BCP or OSQL. Note
that the file is created
by the database server. If you are on 2005, you can also call an Assembly, i
f that suits you better.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:33A04A73-5811-4479-A181-67A3F999C770@.microsoft.com...
> Is it possible to send the output of a query to a text file in a stored
> procedure? When I run stored procedure in Query Analyzer I am able to do t
hat
> and I am wondering if this is possible in a automated way?|||In order to output to a file, you would have to use ( xp_cmdshell and OSQL )
OR bcp.
Check [ BCP Utility ] or [OSQL ] in Book Online
Arnie Rowland, Ph.D.
Westwood Consulting, Inc
Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous
"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:33A04A73-5811-4479-A181-67A3F999C770@.microsoft.com...
> Is it possible to send the output of a query to a text file in a stored
> procedure? When I run stored procedure in Query Analyzer I am able to do
> that
> and I am wondering if this is possible in a automated way?
q; loop for insert into
Hello,
I have 10 tables (T1Orj,T2Orj,…T10Orj) and I need to find modified rows fr
om
each table and insert them to T1Bak, T2Bak, …T10Bak. Although original and
bak tables have the common fields , the original tables have more fields tha
n
bak tables, and T1Orj, T2Orj, … T10Orj tables have different table structu
res.
I can go head and write a insert into query for each table, I am just
wondering Is there any way I can do this in a loop for all tables?"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:044F928B-258D-4AC3-BF5B-469B7E692C22@.microsoft.com...
> Hello,
> I have 10 tables (T1Orj,T2Orj,.T10Orj) and I need to find modified rows
> from
> each table and insert them to T1Bak, T2Bak, .T10Bak. Although original and
> bak tables have the common fields , the original tables have more fields
> than
> bak tables, and T1Orj, T2Orj, . T10Orj tables have different table
> structures.
> I can go head and write a insert into query for each table, I am just
> wondering Is there any way I can do this in a loop for all tables?
>
Do you mean the Orj tables all have the same columns? Why? It would be a lot
simpler to combine them into one. Duplicating tables is almost always a
mistake.
If they are all different then I don't understand how you expect a loop
would help you.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Thanks for the reply, some type of loop might help me if I can get column
names and table names created dynamically from a table. Then I will perform
only one insert in my code.
"David Portas" wrote:
> "JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
> news:044F928B-258D-4AC3-BF5B-469B7E692C22@.microsoft.com...
> Do you mean the Orj tables all have the same columns? Why? It would be a l
ot
> simpler to combine them into one. Duplicating tables is almost always a
> mistake.
> If they are all different then I don't understand how you expect a loop
> would help you.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>
>
I have 10 tables (T1Orj,T2Orj,…T10Orj) and I need to find modified rows fr
om
each table and insert them to T1Bak, T2Bak, …T10Bak. Although original and
bak tables have the common fields , the original tables have more fields tha
n
bak tables, and T1Orj, T2Orj, … T10Orj tables have different table structu
res.
I can go head and write a insert into query for each table, I am just
wondering Is there any way I can do this in a loop for all tables?"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:044F928B-258D-4AC3-BF5B-469B7E692C22@.microsoft.com...
> Hello,
> I have 10 tables (T1Orj,T2Orj,.T10Orj) and I need to find modified rows
> from
> each table and insert them to T1Bak, T2Bak, .T10Bak. Although original and
> bak tables have the common fields , the original tables have more fields
> than
> bak tables, and T1Orj, T2Orj, . T10Orj tables have different table
> structures.
> I can go head and write a insert into query for each table, I am just
> wondering Is there any way I can do this in a loop for all tables?
>
Do you mean the Orj tables all have the same columns? Why? It would be a lot
simpler to combine them into one. Duplicating tables is almost always a
mistake.
If they are all different then I don't understand how you expect a loop
would help you.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Thanks for the reply, some type of loop might help me if I can get column
names and table names created dynamically from a table. Then I will perform
only one insert in my code.
"David Portas" wrote:
> "JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
> news:044F928B-258D-4AC3-BF5B-469B7E692C22@.microsoft.com...
> Do you mean the Orj tables all have the same columns? Why? It would be a l
ot
> simpler to combine them into one. Duplicating tables is almost always a
> mistake.
> If they are all different then I don't understand how you expect a loop
> would help you.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>
>
Saturday, February 25, 2012
q; loop for insert into
Hello,
I have 10 tables (T1Orj,T2Orj,â?¦T10Orj) and I need to find modified rows from
each table and insert them to T1Bak, T2Bak, â?¦T10Bak. Although original and
bak tables have the common fields , the original tables have more fields than
bak tables, and T1Orj, T2Orj, â?¦ T10Orj tables have different table structures.
I can go head and write a insert into query for each table, I am just
wondering Is there any way I can do this in a loop for all tables?"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:044F928B-258D-4AC3-BF5B-469B7E692C22@.microsoft.com...
> Hello,
> I have 10 tables (T1Orj,T2Orj,.T10Orj) and I need to find modified rows
> from
> each table and insert them to T1Bak, T2Bak, .T10Bak. Although original and
> bak tables have the common fields , the original tables have more fields
> than
> bak tables, and T1Orj, T2Orj, . T10Orj tables have different table
> structures.
> I can go head and write a insert into query for each table, I am just
> wondering Is there any way I can do this in a loop for all tables?
>
Do you mean the Orj tables all have the same columns? Why? It would be a lot
simpler to combine them into one. Duplicating tables is almost always a
mistake.
If they are all different then I don't understand how you expect a loop
would help you.
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Thanks for the reply, some type of loop might help me if I can get column
names and table names created dynamically from a table. Then I will perform
only one insert in my code.
"David Portas" wrote:
> "JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
> news:044F928B-258D-4AC3-BF5B-469B7E692C22@.microsoft.com...
> > Hello,
> > I have 10 tables (T1Orj,T2Orj,.T10Orj) and I need to find modified rows
> > from
> > each table and insert them to T1Bak, T2Bak, .T10Bak. Although original and
> > bak tables have the common fields , the original tables have more fields
> > than
> > bak tables, and T1Orj, T2Orj, . T10Orj tables have different table
> > structures.
> > I can go head and write a insert into query for each table, I am just
> > wondering Is there any way I can do this in a loop for all tables?
> >
> Do you mean the Orj tables all have the same columns? Why? It would be a lot
> simpler to combine them into one. Duplicating tables is almost always a
> mistake.
> If they are all different then I don't understand how you expect a loop
> would help you.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>
>
I have 10 tables (T1Orj,T2Orj,â?¦T10Orj) and I need to find modified rows from
each table and insert them to T1Bak, T2Bak, â?¦T10Bak. Although original and
bak tables have the common fields , the original tables have more fields than
bak tables, and T1Orj, T2Orj, â?¦ T10Orj tables have different table structures.
I can go head and write a insert into query for each table, I am just
wondering Is there any way I can do this in a loop for all tables?"JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
news:044F928B-258D-4AC3-BF5B-469B7E692C22@.microsoft.com...
> Hello,
> I have 10 tables (T1Orj,T2Orj,.T10Orj) and I need to find modified rows
> from
> each table and insert them to T1Bak, T2Bak, .T10Bak. Although original and
> bak tables have the common fields , the original tables have more fields
> than
> bak tables, and T1Orj, T2Orj, . T10Orj tables have different table
> structures.
> I can go head and write a insert into query for each table, I am just
> wondering Is there any way I can do this in a loop for all tables?
>
Do you mean the Orj tables all have the same columns? Why? It would be a lot
simpler to combine them into one. Duplicating tables is almost always a
mistake.
If they are all different then I don't understand how you expect a loop
would help you.
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Thanks for the reply, some type of loop might help me if I can get column
names and table names created dynamically from a table. Then I will perform
only one insert in my code.
"David Portas" wrote:
> "JIM.H." <JIMH@.discussions.microsoft.com> wrote in message
> news:044F928B-258D-4AC3-BF5B-469B7E692C22@.microsoft.com...
> > Hello,
> > I have 10 tables (T1Orj,T2Orj,.T10Orj) and I need to find modified rows
> > from
> > each table and insert them to T1Bak, T2Bak, .T10Bak. Although original and
> > bak tables have the common fields , the original tables have more fields
> > than
> > bak tables, and T1Orj, T2Orj, . T10Orj tables have different table
> > structures.
> > I can go head and write a insert into query for each table, I am just
> > wondering Is there any way I can do this in a loop for all tables?
> >
> Do you mean the Orj tables all have the same columns? Why? It would be a lot
> simpler to combine them into one. Duplicating tables is almost always a
> mistake.
> If they are all different then I don't understand how you expect a loop
> would help you.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>
>
Subscribe to:
Posts (Atom)