November 2007
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
Search

 
Catagories
Archives
Recent Entries
Links
RSS

February 28, 2006

query analyzer, keyboard shortcuts

Catagory: sql server · This Entry · Comment(1) · eMail entry · Google
sql server

similar to visual studio, a few gems here.

read more...
 
Posted by 7hz at 10:24 AM | Comments (1)

February 08, 2006

norton & sql server

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

norton antivirus has been preventing sql server 2000 from starting up -- causing this event log :

Error: 17883, Severity: 1, State: 0
The Scheduler 0 appears to be hung. SPID 0, ECID 0, UMS Context 0x02EFA3C8

disabiling norton (or excluding all relevant sql server directories from nav), will set things straight. many DBA's will tell you norton is a problem. in rare cases the only solution is to remove nav entirely. yes.

read more...
 
Posted by 7hz at 11:48 AM | Comments (0)

April 21, 2005

update with var assignment

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

here's an example of how you can perform a variable assignment in an sql update statement. each row processed by the update *also* performs the assignment.

the key is to use this syntax...

SET @x = MyIntegerColumn = @x + 1

this example just increments a value - so each row updated gets a higher value (most cases you would use an index for such a task).

read more...
 
Posted by 7hz at 03:10 PM | Comments (0)

pivot row into a comma delimited list

Catagory: sql server · This Entry · Comment(1) · eMail entry · Google
sql server

ok, whoa, just picked this one up. usually variable assignment from a select statement is thought of as returning one final *single* value (whatever that happens to be).

if instead you perform some logical operations a variable in the meantime you can also continuously calculate and update a variable based on each subsequent row returned.

read more...
 
Posted by 7hz at 02:31 PM | Comments (1)

January 11, 2005

DTS & sql agent ownership problem

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

i'm having trouble with a sql job calling a dts package. the dts package runs fine, but does not run when executed from a job (my domain account is set as owner of the job, and i'm a system admin as well - but the sql server agent is a local account not a domain account)

ordinarily that would be fine - i'm the owner of the job so when the agent executes the job it should use the security context of my account. however i believe there is an additional twist to that, related to DTS packages. here's the catch . . .

read more...
 
Posted by 7hz at 03:32 PM | Comments (0)

DTS returns success even when step fails

Catagory: sql server · This Entry · Comment(1) · eMail entry · Google
sql server

I have a DTS package that calls another DTS package. For the first time, I noticed behavior where the subordinate package fails, but the calling package did not error and stop processing (all using the 'continue on success' workflow properties).

unlike other packages that do this properly without issue, i went ahead checked the "fail package on first error" property under error handling on the subordinate package - then the calling package stopped on that step as desired.

my theory is that the type of error causing the subordinate package to stop was not reported as an error in the same manner to the calling package - that's a feature or bug i'm not sure ?!

read more...
 
Posted by 7hz at 03:23 PM | Comments (1)

January 10, 2005

sql server error 7405

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

BUG: Can't Use SQL Enterprise Manager to Create Stored Procedures Containing Linked Server Objects




Applies to: Microsoft SQL Server 2000 Standard Edition
Article ID : 296769
Last Review : October 3, 2003
Revision : 1.0

This article was previously published under MSKB: Q296769

read more...
 
Posted by 7hz at 01:23 PM | Comments (0)

November 19, 2004

deleting duplicates (more)

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

here's a version uses a self join, on a derivative table instead of a view... this example uses "mytableid" to distinguish records (by adding a index there) - but you might have used "mydatefield" in a similar manner (assuming the date field differentiates the records, and you adjust the comparisons around accordingly).

read more...
 

Posted by 7hz at 11:39 AM | Comments (0)

November 09, 2004

sql job accounts and sqlagent

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

the user (or security context) a sql job runs under varies based on how the job is launched. meaning you might have tested everything, and it's all working fine - only to find your scheduled task fails (with something along the lines of 'access denied').

read more...
 
Posted by 7hz at 03:39 PM | Comments (0)

maintenance plan, error 5070

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

i got an error while executing a database maintenance plan. looking into it closer, revealed that the plan was performing an integrity check with the repair option set.

read more...
 
Posted by 7hz at 02:57 PM | Comments (0)

binary files differ, vss file types

Catagory: programming · This Entry · Comment(0) · eMail entry · Google
programming

visual source safe doesn't always recognize text file types properly. when checking-in files using 'auto' type -- it treats them as binary.

read more...
 
Posted by 7hz at 02:38 PM | Comments (0)

November 01, 2004

enterprise mananger taskpad view error

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

i get the following error sometimes when i click on a database in Enterprise Manager in Task Pad View:



Internet Explorer Script Error
Line: 307
Char: 2
Error: Unspecified Error
Code: 0
URL: res://C:\Program%20Files\Microsoft%20SQL%20Server\80
\Tools\Binn\Resources\1033\sqlmmc.rll/Tabs.html
Do you want to continue running scripts?
Yes|No


This is a problem with Enterprise manager gui...

read more...
 
Posted by 7hz at 02:28 PM | Comments (0)

October 27, 2004

ordering views

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

'Order by', in SQL Views :

SQL Server usually doesn't allow an ORDER BY clause in views. However, you can use this workaround: Just add a TOP 100 PERCENT clause to the front of the SELECT list.

read more...
 
Posted by 7hz at 02:26 PM | Comments (0)

June 29, 2004

maximum page size in sql server

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

What is the Maximum Page Size in SQL Server 2000?

read more...
 
Posted by 7hz at 02:15 PM | Comments (0)

June 28, 2004

tree hierarchies in sql server

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

different ways to handle a tree hierarchies in sql server...

read more...
 
Posted by 7hz at 11:24 AM | Comments (0)

June 24, 2004

ms access left outer join

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

i'm not a big fan, but sometimes ms access makes for a decent tool. however, syntax for various sql operations are different. access can still perform a left outer join, here's how...

read more...
 
Posted by 7hz at 04:52 PM | Comments (0)

June 16, 2004

case insensitive searches

Catagory: sql server · This Entry · Comment(1) · eMail entry · Google
sql server

A default SQL Server installation is case insensitive, which means that SQL Server will not differentiate between upper and lower case characters/letters.

Here are some ways to perform case sensitive searches using different methods.

read more...
 
Posted by 7hz at 02:21 PM | Comments (1)

computed columns and indexes

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

computed columns have some benefits, along with some restrictions (like being deterministic). what's interesting is that SQL doesn't necessarily store the computed column data...

read more...
 
Posted by 7hz at 12:10 PM | Comments (0)

datetime cast

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

more ways to get/deal with datetime values...

read more...
 
Posted by 7hz at 10:54 AM | Comments (0)

June 15, 2004

set v. select

Catagory: sql server · This Entry · Comment(2) · eMail entry · Google
sql server

What is the difference between SET and SELECT when assigning values to variables, in T-SQL?

read more...
 
Posted by 7hz at 11:26 AM | Comments (2)

June 10, 2004

sub queries and result sets

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

while writing a query that seemed straight forward to me, i got the error : "Cannot perform an aggregate function on an expression containing an aggregate or a subquery."

the issue perhaps wasn't the logic of what i was trying to accomplish, but just the order and placement of operations.

the solution? you can always collect your data into a temp table and then work with that. but you don't have to...

read more...
 

Posted by 7hz at 06:11 PM | Comments (0)

stored procedure parameters

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

i actualy forgot you can do this (got used to stuffing paramters in order!)...

you can explicitly name your parameters inline (in the TSQL exec string).

read more...
 
Posted by 7hz at 05:27 PM | Comments (0)

June 07, 2004

date strings

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

i've explored a few more date to string format conversions. nothing really new here, but here are some observations.

read more...
 
Posted by 7hz at 02:59 PM | Comments (0)

April 22, 2004

date comparison / first of month

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

there are a few ways to compare days, or return the first day of the month in sql server.

read more...
 
Posted by 7hz at 05:59 PM | Comments (0)

April 19, 2004

rename or (force) drop database

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

here's a way to rename, or force a database drop. i'm not sure if you need or want the rollback transaction lines. but here you go...

also on renaming, you could dettach the database, move the data / log files, then reattach.

read more...
 
Posted by 7hz at 05:01 PM | Comments (0)

April 15, 2004

it's your birthday...

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

here's a way to calculate someone's age on a given date. also, you can also sort by birthday (month/day) excluding the year.

the query just performs a datediff, BUT adjusts by 0/1 given the time of year -- before or after the person's birthday.

i.e. you just need to adjust by "-1" if the date you're evaluating is prior to the birthday in that year.

read more...
 
Posted by 7hz at 04:32 PM | Comments (0)

April 13, 2004

can't log into database?

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

This throws me off now and then. I quickly create a database in EnterpriseManager then run a script to create objects using Query Analyzer. Since I can to log in as 'sa', everything seems fine -- but I can't log in using a connection string even though 'sa' *should* be the dbo for the database. so what's going on? there's a catch.

read more...
 
Posted by 7hz at 02:42 PM | Comments (0)

April 01, 2004

check for daylight saving time

Catagory: sql server · This Entry · Comment(3) · eMail entry · Google
sql server

This procedure uses the sDayOfMonth procedure, to get the calendar day, then checks if that day is subject to daylight saving time.

This procedure is only accurate to the "day" and not the *hours* prior to the change at 2am (which was just fine for my application).

read more...
 
Posted by 7hz at 11:35 AM | Comments (3)

determine the calendar day of month

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

Here's a stored procedure that returns the calendar "day of month number", given the year, month, and occurance (1st,2nd,...) and the day of week in question (sunday,monday,...).

I used this for another procedure that determines if daylight saving time is in effect on a given day. see the notes regarding validating input for other use cases, but it should be quite useful.

read more...
 
Posted by 7hz at 11:26 AM | Comments (0)

March 16, 2004

adding a composite column constraint

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

unique constraints are actually implemented as indexes really, so it might not be obvious where to go to do this in enterprise manager.

to add a unique composite column constraint in sql server, you can bring up the design table dialog (right click on the table) in enterprise manager, then click on indexes and keys.

read more...
 
Posted by 7hz at 04:27 PM | Comments (0)

March 07, 2004

cross database join

Catagory: sql server · This Entry · Comment(0) · eMail entry · Google
sql server

Make sure to install service pack 3 on SQL Server 2000 -- and check "enable cross ownership chaining".

otherwise you'll have to grant permissions on individual tables (beyond what you might expect to get that to work), as a workaround

Posted by 7hz at 05:06 PM | Comments (0)