Showing posts with label specific. Show all posts
Showing posts with label specific. Show all posts

Thursday, March 29, 2012

case statement in where clause

I need a SQL statement that selects a specific year (@.yr type int) in the "createddate" column...if this @.yr is equal to 0 then I want to select ALL columns regardless of the year...

This is what I have so far, but it doesnt work...

SELECT * FROM tblUsers
WHERE year(CreatedDate)=CASE
WHEN @.yr<>'0' THEN @.yr
ELSE NOT NULL
END

SELECT * FROM tblUsers
WHERE year(CreatedDate)=CASE WHEN (@.yr= 0) THEN year(CreatedDate) ELSE @.yr END


Saturday, February 25, 2012

Capturing operations and tSQL executed under a user account

All,
I am looking for a way to capture all of the SQL code executed against a
database by a specific user.
Currently, a SQL 2005 database is being maintained by a third party that
connects remotely and does occasional "maintenance." The client would like
to bring this operation in house and is looking for a way to capture these
activities so that they can be documented.
The accuracy of this is essential so we are looking for a way to do a direct
capture.
Suggestions?
Ryan Hanisco
MCSE, MCTS: SQL 2005, Project+
Chicago, IL
Remember: Marking helpful answers helps everyone find the info they need
quickly.
On Jun 7, 4:06 pm, Ryan Hanisco
<RyanHani...@.discussions.microsoft.com> wrote:
> All,
> I am looking for a way to capture all of the SQL code executed against a
> database by a specific user.
> Currently, a SQL 2005 database is being maintained by a third party that
> connects remotely and does occasional "maintenance." The client would like
> to bring this operation in house and is looking for a way to capture these
> activities so that they can be documented.
> The accuracy of this is essential so we are looking for a way to do a direct
> capture.
> Suggestions?
The easy way is to use Profiler. (That's what they called it in SQL
2000, it's undoubtedly there in SQL 2005 but possibly under a new
name.)
If you have to do it the hard way, look at the sp_trace stored
procedure.
|||Ryan Hanisco (RyanHanisco@.discussions.microsoft.com) writes:
> I am looking for a way to capture all of the SQL code executed against a
> database by a specific user.
> Currently, a SQL 2005 database is being maintained by a third party that
> connects remotely and does occasional "maintenance." The client would
> like to bring this operation in house and is looking for a way to
> capture these activities so that they can be documented.
> The accuracy of this is essential so we are looking for a way to do a
> direct capture.
This is precisely what SQL Profiler is good for. Or a server side trace,
if you want to reduce the load.
Although, this appears to me a somewhat funny thing to document procedures.
It sounds more like eavesdropping to me.n
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Sunday, February 19, 2012

Capture delta or SQL DML

Is it possible to capture delta for a specific table or capture DML statemen
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

Is it possible to capture delta for a specific table or capture DML statement
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:

Thursday, February 16, 2012

Capitalisation

Hi Guys

Anybody tell me where of if there is a setting to set
whether or not the fields and table names need to be case
specific on SQL 2000.

I've been using SQL Server 7 where it has not been the case that the table and field names had had to be the same capitalisation-wise in running.

ie select * from tbl_example would work if the table name was Tbl_Example

I've just been trying to run the same queries on a different
server, which is running SQL 2000, and they won't execute unless the
capitalisation on the table and field names are exactly
the same.

There must be a simple setting somewhere please!You must change the collation settings. To change one or more of these settings, you must rebuild the master and user databases.

How to rebuild the master database (Rebuild Master utility)
To rebuild the master database

Shutdown Microsoft SQL Server 2000, and then run Rebuildm.exe. This is located in the Program Files\Microsoft SQL Server\80\Tools\Binn directory.

In the Rebuild Master dialog box, click Browse.

In the Browse for Folder dialog box, select the \Data folder on the SQL Server 2000 compact disc or in the shared network directory from which SQL Server 2000 was installed, and then click OK.

Click Settings. In the Collation Settings dialog box, verify or change settings used for the master database and all other databases.
Initially, the default collation settings are shown, but these may not match the collation selected during setup. You can select the same settings used during setup or select new collation settings. When done, click OK.

In the Rebuild Master dialog box, click Rebuild to start the process.
The Rebuild Master utility reinstalls the master database.

Note To continue, you may need to stop a server that is running.

Needless to say, you have to be extremely careful if you are trying to re-build your master or user databases. So I would suggest you do it only if it is abosolutely necessary. Refer to BOL for more information.

All the best

Originally posted by garethimh
Hi Guys

Anybody tell me where of if there is a setting to set
whether or not the fields and table names need to be case
specific on SQL 2000.

I've been using SQL Server 7 where it has not been the case that the table and field names had had to be the same capitalisation-wise in running.

ie select * from tbl_example would work if the table name was Tbl_Example

I've just been trying to run the same queries on a different
server, which is running SQL 2000, and they won't execute unless the
capitalisation on the table and field names are exactly
the same.

There must be a simple setting somewhere please!|||Originally posted by sbaru
You must change the collation settings. To change one or more of these settings, you must rebuild the master and user databases.

How to rebuild the master database (Rebuild Master utility)
To rebuild the master database

Shutdown Microsoft SQL Server 2000, and then run Rebuildm.exe. This is located in the Program Files\Microsoft SQL Server\80\Tools\Binn directory.

In the Rebuild Master dialog box, click Browse.

In the Browse for Folder dialog box, select the \Data folder on the SQL Server 2000 compact disc or in the shared network directory from which SQL Server 2000 was installed, and then click OK.

Click Settings. In the Collation Settings dialog box, verify or change settings used for the master database and all other databases.
Initially, the default collation settings are shown, but these may not match the collation selected during setup. You can select the same settings used during setup or select new collation settings. When done, click OK.

In the Rebuild Master dialog box, click Rebuild to start the process.
The Rebuild Master utility reinstalls the master database.

Note To continue, you may need to stop a server that is running.

Needless to say, you have to be extremely careful if you are trying to re-build your master or user databases. So I would suggest you do it only if it is abosolutely necessary. Refer to BOL for more information.

All the best

Brilliant, thanks!|||sbaru's suggetion is dead on but remember to make a backup of everything first.