Tuesday, March 27, 2012
Case statement
statement similar to the following?
DECLARE @.path_f1 nvarchar(200)
DECLARE @.path_f2 nvarchar(200)
SELECT
@.path_f1 = output_path_file1,
@.path_f2 = output_path_file2
FROM t1
WHERE t1id = 1
SELECT
CASE
WHEN f1_status = 0 THEN
UPDATE t1
SET f1_status = 1, f1_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f1, null
WHEN f1_status = 1 AND f2_status = 0 THEN
UPDATE t1
SET file2_status = 1, file2_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f2, null
ELSE
RAISERROR ('Error Message', 16,1)
END
FROM t1
WHERE t1id = 1
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200603/1Not the way you're doing it. You can have something along the lines of:
UPDATE t1
SET
f1_status = CASE
WHEN f1_status = 0 THEN 1
ELSE f1_status END
, f1_created = CASE
WHEN f1_status = 0 THEN getdate()
ELSE f1_created END
WHERE t1id = 1
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"cbrichards via SQLMonster.com" <u3288@.uwe> wrote in message
news:5df3ff92c5d28@.uwe...
Is it possible to have multiple expressions, or dml expressions in a case
statement similar to the following?
DECLARE @.path_f1 nvarchar(200)
DECLARE @.path_f2 nvarchar(200)
SELECT
@.path_f1 = output_path_file1,
@.path_f2 = output_path_file2
FROM t1
WHERE t1id = 1
SELECT
CASE
WHEN f1_status = 0 THEN
UPDATE t1
SET f1_status = 1, f1_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f1, null
WHEN f1_status = 1 AND f2_status = 0 THEN
UPDATE t1
SET file2_status = 1, file2_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f2, null
ELSE
RAISERROR ('Error Message', 16,1)
END
FROM t1
WHERE t1id = 1
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200603/1|||The issue would become very straightforward and simple only if one stops
using the phrase 'a CASE statement' because there is no such a thing, and
starts using 'a CASE expression.'
Linchi
"cbrichards via SQLMonster.com" wrote:
> Is it possible to have multiple expressions, or dml expressions in a case
> statement similar to the following?
> DECLARE @.path_f1 nvarchar(200)
> DECLARE @.path_f2 nvarchar(200)
> SELECT
> @.path_f1 = output_path_file1,
> @.path_f2 = output_path_file2
> FROM t1
> WHERE t1id = 1
> SELECT
> CASE
> WHEN f1_status = 0 THEN
> UPDATE t1
> SET f1_status = 1, f1_created = getdate()
> WHERE t1id = 1
> EXEC usp_t1 @.path_f1, null
> WHEN f1_status = 1 AND f2_status = 0 THEN
> UPDATE t1
> SET file2_status = 1, file2_created = getdate()
> WHERE t1id = 1
> EXEC usp_t1 @.path_f2, null
> ELSE
> RAISERROR ('Error Message', 16,1)
> END
> FROM t1
> WHERE t1id = 1
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200603/1
>
Case statement
statement similar to the following?
DECLARE @.path_f1 nvarchar(200)
DECLARE @.path_f2 nvarchar(200)
SELECT
@.path_f1 = output_path_file1,
@.path_f2 = output_path_file2
FROM t1
WHERE t1id = 1
SELECT
CASE
WHEN f1_status = 0 THEN
UPDATE t1
SET f1_status = 1, f1_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f1, null
WHEN f1_status = 1 AND f2_status = 0 THEN
UPDATE t1
SET file2_status = 1, file2_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f2, null
ELSE
RAISERROR ('Error Message', 16,1)
END
FROM t1
WHERE t1id = 1
Message posted via droptable.com
http://www.droptable.com/Uwe/Forums...erver/200603/1
Not the way you're doing it. You can have something along the lines of:
UPDATE t1
SET
f1_status = CASE
WHEN f1_status = 0 THEN 1
ELSE f1_status END
, f1_created = CASE
WHEN f1_status = 0 THEN getdate()
ELSE f1_created END
WHERE t1id = 1
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"cbrichards via droptable.com" <u3288@.uwe> wrote in message
news:5df3ff92c5d28@.uwe...
Is it possible to have multiple expressions, or dml expressions in a case
statement similar to the following?
DECLARE @.path_f1 nvarchar(200)
DECLARE @.path_f2 nvarchar(200)
SELECT
@.path_f1 = output_path_file1,
@.path_f2 = output_path_file2
FROM t1
WHERE t1id = 1
SELECT
CASE
WHEN f1_status = 0 THEN
UPDATE t1
SET f1_status = 1, f1_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f1, null
WHEN f1_status = 1 AND f2_status = 0 THEN
UPDATE t1
SET file2_status = 1, file2_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f2, null
ELSE
RAISERROR ('Error Message', 16,1)
END
FROM t1
WHERE t1id = 1
Message posted via droptable.com
http://www.droptable.com/Uwe/Forums...erver/200603/1
|||The issue would become very straightforward and simple only if one stops
using the phrase 'a CASE statement' because there is no such a thing, and
starts using 'a CASE expression.'
Linchi
"cbrichards via droptable.com" wrote:
> Is it possible to have multiple expressions, or dml expressions in a case
> statement similar to the following?
> DECLARE @.path_f1 nvarchar(200)
> DECLARE @.path_f2 nvarchar(200)
> SELECT
> @.path_f1 = output_path_file1,
> @.path_f2 = output_path_file2
> FROM t1
> WHERE t1id = 1
> SELECT
> CASE
> WHEN f1_status = 0 THEN
> UPDATE t1
> SET f1_status = 1, f1_created = getdate()
> WHERE t1id = 1
> EXEC usp_t1 @.path_f1, null
> WHEN f1_status = 1 AND f2_status = 0 THEN
> UPDATE t1
> SET file2_status = 1, file2_created = getdate()
> WHERE t1id = 1
> EXEC usp_t1 @.path_f2, null
> ELSE
> RAISERROR ('Error Message', 16,1)
> END
> FROM t1
> WHERE t1id = 1
> --
> Message posted via droptable.com
> http://www.droptable.com/Uwe/Forums...erver/200603/1
>
Case statement
statement similar to the following?
DECLARE @.path_f1 nvarchar(200)
DECLARE @.path_f2 nvarchar(200)
SELECT
@.path_f1 = output_path_file1,
@.path_f2 = output_path_file2
FROM t1
WHERE t1id = 1
SELECT
CASE
WHEN f1_status = 0 THEN
UPDATE t1
SET f1_status = 1, f1_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f1, null
WHEN f1_status = 1 AND f2_status = 0 THEN
UPDATE t1
SET file2_status = 1, file2_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f2, null
ELSE
RAISERROR ('Error Message', 16,1)
END
FROM t1
WHERE t1id = 1
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...server/200603/1Not the way you're doing it. You can have something along the lines of:
UPDATE t1
SET
f1_status = CASE
WHEN f1_status = 0 THEN 1
ELSE f1_status END
, f1_created = CASE
WHEN f1_status = 0 THEN getdate()
ELSE f1_created END
WHERE t1id = 1
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"cbrichards via droptable.com" <u3288@.uwe> wrote in message
news:5df3ff92c5d28@.uwe...
Is it possible to have multiple expressions, or dml expressions in a case
statement similar to the following?
DECLARE @.path_f1 nvarchar(200)
DECLARE @.path_f2 nvarchar(200)
SELECT
@.path_f1 = output_path_file1,
@.path_f2 = output_path_file2
FROM t1
WHERE t1id = 1
SELECT
CASE
WHEN f1_status = 0 THEN
UPDATE t1
SET f1_status = 1, f1_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f1, null
WHEN f1_status = 1 AND f2_status = 0 THEN
UPDATE t1
SET file2_status = 1, file2_created = getdate()
WHERE t1id = 1
EXEC usp_t1 @.path_f2, null
ELSE
RAISERROR ('Error Message', 16,1)
END
FROM t1
WHERE t1id = 1
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...server/200603/1|||The issue would become very straightforward and simple only if one stops
using the phrase 'a CASE statement' because there is no such a thing, and
starts using 'a CASE expression.'
Linchi
"cbrichards via droptable.com" wrote:
> Is it possible to have multiple expressions, or dml expressions in a case
> statement similar to the following?
> DECLARE @.path_f1 nvarchar(200)
> DECLARE @.path_f2 nvarchar(200)
> SELECT
> @.path_f1 = output_path_file1,
> @.path_f2 = output_path_file2
> FROM t1
> WHERE t1id = 1
> SELECT
> CASE
> WHEN f1_status = 0 THEN
> UPDATE t1
> SET f1_status = 1, f1_created = getdate()
> WHERE t1id = 1
> EXEC usp_t1 @.path_f1, null
> WHEN f1_status = 1 AND f2_status = 0 THEN
> UPDATE t1
> SET file2_status = 1, file2_created = getdate()
> WHERE t1id = 1
> EXEC usp_t1 @.path_f2, null
> ELSE
> RAISERROR ('Error Message', 16,1)
> END
> FROM t1
> WHERE t1id = 1
> --
> Message posted via droptable.com
> http://www.droptable.com/Uwe/Forum...server/200603/1
>sql
Sunday, February 19, 2012
CAPTURE DML FROM TRIGGER
Hi All!
SQL Server 2000
I've situation where I've to capture a DML executing against let say Table1 and later may at the end of the day or week I want to be able to extract all the DML executed against Table1 and execute them against similar tables on different sql server to synchronize the data. I don't want to use profiler as this is quite expensive resource for my problem niether can use any third party tool.
Is it possible to capture sql statement in the trigger?
I hope I made my question clear. Urgent help will be highly appreciated.
--Sohail.
There is no way to obtain this information accurately in SQL Server right now. So you will have to run a Profiler trace on the desired table and filter the statements. We are considering adding support for obtaining the DML statement that caused a trigger to fire in a future release.|||If you're just capturing the DML to replicate it on a different server then do you need the actual DML?
Why not just a trigger to log which rows have been updated then when you run your replication batch you can easily copy the relavent data over (or delete where appropriate)
Capture delta or SQL DML
t
executed against a specific table?
thanks> Is it possible to capture delta for a specific table or capture DML
> statement
> executed against a specific table?
With SQL Server, you get SQL Profiler that enables you to catch any
statement sent to SQL Server, including DML statements. Findind differences
in data is quite simple, if you have a stable PK and a timestamp column.
Anyway, you can help yourself with 3rd party tools as well. Some of them
include:
- Red-Gate SQL Compare (http://www.red-gate.com/) helps you comparing the
schema
- Red-Gate SQL Data Compare (http://www.red-gate.com/) helps you comparing
the data
- Lumigent AuditDB helps you with auditing (http://www.lumigent.com/) -
easier than Profiler
Dejan Sarka, SQL Server MVP
Mentor, www.SolidQualityLearning.com
Anything written in this message represents solely the point of view of the
sender.
This message does not imply endorsement from Solid Quality Learning, and it
does not represent the point of view of Solid Quality Learning or any other
person, company or institution mentioned in this message|||The SchemaCrawler tool helps you compare the schema and data of a
database with a reference version. SchemaCrawler outputs details of
your schema (tables, views, procedures, and more) in a diff-able
plain-text format (text, CSV, or XHTML). SchemaCrawler can also output
data (including CLOBs and BLOBs) in the same plain-text formats. You
can use a standard diff program to diff the current output with a
reference version of the output.
SchemaCrawler is free, open-source, cross-platform (operating system
and database) tool, written in Java, that is available at SourceForge:
http://schemacrawler.sourceforge.net/
You will need to provide a JDBC driver for your database. No other
third-party libraries are required. A lot of examples are available
with the download to help you get started.
Sualeh Fatehi.|||Well, Infact I need to capture delta so I can publish it or apply it to the
datawarehouse. Is there any other effective way to do this?
Thanks
"sualeh.fatehi@.gmail.com" wrote:
> The SchemaCrawler tool helps you compare the schema and data of a
> database with a reference version. SchemaCrawler outputs details of
> your schema (tables, views, procedures, and more) in a diff-able
> plain-text format (text, CSV, or XHTML). SchemaCrawler can also output
> data (including CLOBs and BLOBs) in the same plain-text formats. You
> can use a standard diff program to diff the current output with a
> reference version of the output.
> SchemaCrawler is free, open-source, cross-platform (operating system
> and database) tool, written in Java, that is available at SourceForge:
> http://schemacrawler.sourceforge.net/
> You will need to provide a JDBC driver for your database. No other
> third-party libraries are required. A lot of examples are available
> with the download to help you get started.
>
> Sualeh Fatehi.
>|||Shahab,
In fact, SchemaCrawler, when coupled with any standard diff tool will
help you to capture and publish the diffs. Am I missing something in
your use case?
Sualeh Fatehi.|||Seems like schema crawler takes the whole schema. Whereas I am concerned mor
e
with a few defined tables. Hope this clearifies the confusion.
"sualeh.fatehi@.gmail.com" wrote:
> Shahab,
> In fact, SchemaCrawler, when coupled with any standard diff tool will
> help you to capture and publish the diffs. Am I missing something in
> your use case?
> Sualeh Fatehi.
>|||In fact, with SchemaCrawler you can specify exactly which tables, and
which columns are you interested in. Please look at the how-to section
of the website.
http://schemacrawler.sourceforge.net/how-to.html
Sualeh Fatehi.
shahab wrote:
> Seems like schema crawler takes the whole schema. Whereas I am concerned m
ore
> with a few defined tables. Hope this clearifies the confusion.|||Have you thought about putting a trigger on the table that is changing
and having it output the delta to another table?
On Oct 26, 4:08 pm, sualeh.fat...@.gmail.com wrote:[vbcol=seagreen]
> In fact, with SchemaCrawler you can specify exactly which tables, and
> which columns are you interested in. Please look at the how-to section
> of the website.http://schemacrawler.sourceforge.net/how-to.html
> Sualeh Fatehi.
>
> shahab wrote:
Capture delta or SQL DML
executed against a specific table?
thanks
> Is it possible to capture delta for a specific table or capture DML
> statement
> executed against a specific table?
With SQL Server, you get SQL Profiler that enables you to catch any
statement sent to SQL Server, including DML statements. Findind differences
in data is quite simple, if you have a stable PK and a timestamp column.
Anyway, you can help yourself with 3rd party tools as well. Some of them
include:
- Red-Gate SQL Compare (http://www.red-gate.com/) helps you comparing the
schema
- Red-Gate SQL Data Compare (http://www.red-gate.com/) helps you comparing
the data
- Lumigent AuditDB helps you with auditing (http://www.lumigent.com/) -
easier than Profiler
Dejan Sarka, SQL Server MVP
Mentor, www.SolidQualityLearning.com
Anything written in this message represents solely the point of view of the
sender.
This message does not imply endorsement from Solid Quality Learning, and it
does not represent the point of view of Solid Quality Learning or any other
person, company or institution mentioned in this message
|||The SchemaCrawler tool helps you compare the schema and data of a
database with a reference version. SchemaCrawler outputs details of
your schema (tables, views, procedures, and more) in a diff-able
plain-text format (text, CSV, or XHTML). SchemaCrawler can also output
data (including CLOBs and BLOBs) in the same plain-text formats. You
can use a standard diff program to diff the current output with a
reference version of the output.
SchemaCrawler is free, open-source, cross-platform (operating system
and database) tool, written in Java, that is available at SourceForge:
http://schemacrawler.sourceforge.net/
You will need to provide a JDBC driver for your database. No other
third-party libraries are required. A lot of examples are available
with the download to help you get started.
Sualeh Fatehi.
|||The SchemaCrawler tool helps you compare the schema and data of a
database with a reference version. SchemaCrawler outputs details of
your schema (tables, views, procedures, and more) in a diff-able
plain-text format (text, CSV, or XHTML). SchemaCrawler can also output
data (including CLOBs and BLOBs) in the same plain-text formats. You
can use a standard diff program to diff the current output with a
reference version of the output.
SchemaCrawler is free, open-source, cross-platform (operating system
and database) tool, written in Java, that is available at SourceForge:
http://schemacrawler.sourceforge.net/
You will need to provide a JDBC driver for your database. No other
third-party libraries are required. A lot of examples are available
with the download to help you get started.
Sualeh Fatehi.
|||Well, Infact I need to capture delta so I can publish it or apply it to the
datawarehouse. Is there any other effective way to do this?
Thanks
"sualeh.fatehi@.gmail.com" wrote:
> The SchemaCrawler tool helps you compare the schema and data of a
> database with a reference version. SchemaCrawler outputs details of
> your schema (tables, views, procedures, and more) in a diff-able
> plain-text format (text, CSV, or XHTML). SchemaCrawler can also output
> data (including CLOBs and BLOBs) in the same plain-text formats. You
> can use a standard diff program to diff the current output with a
> reference version of the output.
> SchemaCrawler is free, open-source, cross-platform (operating system
> and database) tool, written in Java, that is available at SourceForge:
> http://schemacrawler.sourceforge.net/
> You will need to provide a JDBC driver for your database. No other
> third-party libraries are required. A lot of examples are available
> with the download to help you get started.
>
> Sualeh Fatehi.
>
|||Shahab,
In fact, SchemaCrawler, when coupled with any standard diff tool will
help you to capture and publish the diffs. Am I missing something in
your use case?
Sualeh Fatehi.
|||Seems like schema crawler takes the whole schema. Whereas I am concerned more
with a few defined tables. Hope this clearifies the confusion.
"sualeh.fatehi@.gmail.com" wrote:
> Shahab,
> In fact, SchemaCrawler, when coupled with any standard diff tool will
> help you to capture and publish the diffs. Am I missing something in
> your use case?
> Sualeh Fatehi.
>
|||In fact, with SchemaCrawler you can specify exactly which tables, and
which columns are you interested in. Please look at the how-to section
of the website.
http://schemacrawler.sourceforge.net/how-to.html
Sualeh Fatehi.
shahab wrote:
> Seems like schema crawler takes the whole schema. Whereas I am concerned more
> with a few defined tables. Hope this clearifies the confusion.
|||Have you thought about putting a trigger on the table that is changing
and having it output the delta to another table?
On Oct 26, 4:08 pm, sualeh.fat...@.gmail.com wrote:[vbcol=seagreen]
> In fact, with SchemaCrawler you can specify exactly which tables, and
> which columns are you interested in. Please look at the how-to section
> of the website.http://schemacrawler.sourceforge.net/how-to.html
> Sualeh Fatehi.
>
> shahab wrote: