Removing all extended properties from SQL Server#

About a year ago, we tried using a tool to get our SQL schema into a souce control system.  It was supposed to work like this: every night the process would run and checkin each object as a file into TFS. 

Well, aside from not working, it also added Extended Properties to all our objects in SQL Server. 

Not really a big deal, except when we would run our database comparison tools between production and development these would cause it so that almost everything would appear out of sync.

I ended up writing my own service to check in all our SQL objects into TFS, but we were left with all these Extended Properties all over the place. 

So I finally got around to cleaning them up using the script below:

select 'EXEC sp_dropextendedproperty 
@name = ''' + sys.extended_properties.name + ''' 
,@level0type = ''schema'' 
,@level0name = ' + object_schema_name(extended_properties.major_id) + '
,@level1type = ''' + 
    CASE WHEN  
        xtype = 'U' THEN 'table'
        WHEN 
        xtype = 'FN' THEN 'function'
        WHEN 
        xtype = 'V' THEN 'view'
        WHEN 
        xtype = 'P' THEN 'procedure' end
    + '''
,@level1name = ''' + object_name(extended_properties.major_id) + ''''
from sys.extended_properties
INNER JOIN sysobjects ON sys.extended_properties.major_id  = sysobjects.id
where extended_properties.class_desc = 'OBJECT_OR_COLUMN'
and extended_properties.minor_id = 0
and extended_properties.name like 'VSS%'

This script will produce a record set that you can copy and paste into another query window to run to clean out all the extended properties. 

Note: all the generated extended properties that this tool created on our DB started with "VSS" so that is why I have that extra item in my where clause.  You'll probably want to remove that.

Categories: Programming | Database | SQL Server
Friday, December 11, 2009 11:27:26 AM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

SQL NOT IN and NULL still will not work#

Last night I had another instance where doing a:

SELECT * FROM
TBL WHERE ID NOT IN (SELECT ID FROM TBL2)

would fail every time to return any rows.

After longer than it should have been, I realized that it was this stupid issue that I blogged about already (SQL "NOT IN" Will Fail If The List Contains A Null).

 

Categories: Misc | Programming | Database | SQL Server | T-Sql
Thursday, August 13, 2009 1:07:10 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Debugging SQL Server Deadlock Issues#
Categories: Programming | Database | SQL Server
Friday, July 10, 2009 3:09:10 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Getting error reports when a SQL Reporting Subscription Fails#

UPDATE 2:

Either this never worked in the first place as I wanted, or MS has changed how they are doing things in SSRS 2008.

I now don't see any of the errors in the tables I had been looking in, and in fact, the errors don't show up in any of their logs either.  This is crap.

If you are like me, you don't like the fact that the first time you realize that a data driven subscriptions in SQL Server Reporting Services has been failing is when someone comes up to you and says "Hey, I did XYZ and I never saw the server kick off an email." 

Really?  Let me check.... oh, looks like it has been broken for god knows how long.  What the heck?

Well, I wrote a script to notify you when there are errors on the report server.

First, you need to setup Database Mail.  Expand Management, and pick Database Mail.  For my script I used the name "Email Profile" for the "Email Profile" get it?

Then create a trigger on the ExecutionLogStorage table like this:

USE [ReportServer]
GO
/****** Object:  Trigger [dbo].[ExecutionLogStorage_Insert]    Script Date: 05/13/2009 10:20:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[ExecutionLogStorage_Insert]
ON [dbo].[ExecutionLogStorage]
AFTER INSERT
AS 
BEGIN
    DECLARE @sStatus AS NVARCHAR(32)
    SET @sStatus = (SELECT Status FROM inserted)
    
    IF(@sStatus <> 'rsSuccess')
    BEGIN
        DECLARE @sReportName AS NVARCHAR(425)
        DECLARE @sPath AS NVARCHAR(425)
        DECLARE @ReportId AS UNIQUEIDENTIFIER 
        DECLARE @sUserName AS NVARCHAR(260)
        DECLARE @sParameters AS NVARCHAR(4000)
        DECLARE @dTimeEnd AS DATETIME 
        DECLARE @iTimeProcessing as int
        
        
        SELECT 
          @sReportName = Name,
          @sPath =PATH,
          @ReportId = ReportId,
          @sUserName = username,
          @sParameters = (select CAST(ISNULL(ELS.Parameters,'') AS NVARCHAR(4000)) from ExecutionLogStorage ELS Where LogEntryId = Inserted.LogEntryId),
          @dTimeEnd = TimeEnd,
          @iTimeProcessing = ISNULL(TimeProcessing,0)
        FROM inserted INNER JOIN [Catalog] 
        ON inserted.ReportId = CATALOG.[ItemID] 
        
        DECLARE @sBody VARCHAR(8000)
        SET @sBody = 'Error with SQL Report ' 
                    + CAST(@sReportName AS VARCHAR(100))
                    + ' at path ' 
                    + CAST (@sPath AS VARCHAR(250))
                    + ' with ReportId ' 
                    + CAST(@ReportId AS VARCHAR(100)) 
                    + ' and username ' 
                    + CAST(@sUserName AS VARCHAR(100))
                    + ' Parameters ' 
                    + CAST(@sParameters  AS VARCHAR(5000))
                    + ' End time ' 
                    + CAST(@dTimeEnd AS VARCHAR(50))
                    + ' Status ' 
                    + CAST(@sStatus AS VARCHAR(50))
                    + ' Time Processing '
                    + CAST(@iTimeProcessing AS VARCHAR(50));
        
        DECLARE @sSubject VARCHAR(500)
        SET @sSubject = 'Error With Report ' + @sReportName
        
        EXEC msdb.dbo.sp_send_dbmail 
         @profile_name = 'Email Profile', 
         @recipients = 'email@address.com', 
         @body =  @sBody  ,
         @subject = @sSubject;

    END
    
END

Presto!

 

UPDATE: Added logic to get the status and parameters.

 

Categories: Programming | .Net | Database | SQL Server | T-Sql | Reporting
Wednesday, May 06, 2009 4:55:06 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Finding if SP Parameters are Nullable#

I'm working on something where I wanted to know if some parameters to a SQL Server Stored Procedure were nullable (or, in otherwords, if they had a default value).

The API I was working with provided a way to find info about the SP, but the isNullable value was never accurate.

I tried working with with the MS DAABs which have a way to fetch SP parameter info, but this method also produced faulty information.

Looking into the code of the DAAB, it was internally calling:

Dim command As SqlCommand

SqlCommandBuilder.DeriveParameters(command)

Somewhere I came across some code for the DeriveParameters method (I think from the Mono project maybe?) which showed it calling this system SP:

sp_procedure_params_rowset

Which returns output fields,:

PARAMETER_HASDEFAULT

IS_NULLABLE

But, again, neither of these appear correctly.

However, I finally came across this thread where a MSFT poster indicates that this data is simply not available:

http://social.msdn.microsoft.com/forums/en-US/transactsql/thread/900756fd-3980-48e3-ae59-a15d7fc15b4c/

Instead, you need to parse the SP definition to see what the default parameter value is, which is a pain, but at least I know why these other methods kept not working.

 

Categories: Programming | Database | SQL Server | T-Sql
Saturday, April 25, 2009 10:55:55 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Avoid Overwriting Modified SPs With Code Generation#

One of the challenges of using code generation is to avoid overwriting your custom changes when you re-generate the code later.

This is a trick I am using to avoid overwriting my stored procedures if I update them manually.  The trick is to include a comment indicating that the SP has been code generated, and then to remove that comment if you update the SP.  So lets say that you generate:

CREATE PROCEDURE OrderDetails_Get
@OrderId as int
AS
-- CODE GENERATED
SELECT * FROM
OrderDetails
WHERE
OrderId = @OrderId

and you made some customizations to the SP so it now looks like this:

CREATE PROCEDURE OrderDetails_Get
@OrderId as int
AS
SELECT * FROM
OrderDetails
INNER JOIN
Orders ON
Orders.OrderId = OrderDetails.OrderId
WHERE
OrderId = @OrderId

The following code will help you when generating your SPs to avoid overwriting this change:

IF EXISTS(
  SELECT [definition] AS objectText 
  FROM sys.sql_modules 
  WHERE [object_id] = OBJECT_ID(N'OrderDetails_Get', 'P') 
  AND definition LIKE '%CODE GENERATED%')
BEGIN
   -- overwrite is ok
END

 

Categories: Programming | Database | SQL Server | T-Sql
Saturday, April 18, 2009 9:37:55 AM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

SQL Server encountered error 0x80070422 (FIXED)#

Today we started getting this error when trying to do full text search with SQL Server 2008.

Msg 30046, Level 16, State 1, Procedure CodeMaster_GetCostCodesByCriteria_FullText, Line 47

SQL Server encountered error 0x80070422 while communicating with full-text filter daemon host (FDHost) process. Make sure that the FDHost process is running. To re-start the FDHost process, run the sp_fulltext_service 'restart_all_fdhosts' command or restart the SQL Server instance.

Google has NOTHING on this problem, except 1 other guy reporting it to MS, who tells him to go to some other forum.

Great.

If I find anything I will post it.

UPDATE:

Ok I figured this out.

The problem was that the actual FTS service was disabled (but not just that, so read on).

So go into your services and make sure that this one is running:

SQL Full-text Filter Daemon Launcher (MSSQLSERVER)

But even after I set this up running things weren't working.  More research led me to find out that there was an issue with the fact that we run our SQL Server under a domain account and the full text search was not running as that same user.

So I configured this service to run as the same user and restarted the service.

Then in SQL Server I ran this:

EXEC sp_fulltext_service 'restart_all_fdhosts'

to restart things.

I also right clicked on the FTS catalog (under databasename/Storage/Full Text Catalog), picked properties, and then selected the option to rebuild catalog.

 

Categories: Programming | Database | SQL Server
Thursday, February 26, 2009 3:51:10 PM (Central Standard Time, UTC-06:00) #    Comments [2]  | 

 

Checking and Updating Identity Seed in SQL Server#

If you want to check and update the identity on tables in SQL Server, you can use the following code:

select ident_current('tablename') as ident
dbcc checkident('tablename',RESEED,100)
select ident_current('tablename') as newident

 

Categories: Programming | Database | SQL Server | T-Sql
Thursday, January 29, 2009 9:13:29 AM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

SQL Reporting Services Subscription Ownership#

We utilize data driven subscriptions in SQL Server Reporting Services (SSRS) to automate several reports and their distribution to a group of people.  For example maybe when a work order is created in the database a report with info about that order is emailed to everyone who will have to be involved in fulfiling the order. 

We realized that some of these reports were not going out.  By looking at the log files (located at ) it became clear that we were hitting a permissions issue:

ReportingServicesService!library!4!09/25/2008-08:15:04:: 
e ERROR: Throwing Microsoft.ReportingServices.Diagnostics.Utilities.AccessDeniedException:
The permissions granted to user 'MYDOMAIN\someuser' are insufficient for performing this operation., ; Info: Microsoft.ReportingServices.Diagnostics.Utilities.AccessDeniedException:
The permissions granted to user 'MYDOMAIN\someuser' are insufficient for performing this operation.

Ok that seemed to make sense.  The user "someuser" had left our company and so I'm sure his account was disabled.  After looking around at the report, it's definition, the subscriptions, the data access, nothing was tied to this old employee. 

But.... the subscription itself still is.

The downside of this is that there is no way to change who "owns" the subscription.

However, you can make the changes manually in the database with the following code:

DECLARE @OldUserID uniqueidentifier
DECLARE @NewUserID uniqueidentifier 

SELECT @OldUserID = UserID FROM dbo.Users 
WHERE UserName = 'MYDOMAIN\someuser'

SELECT @NewUserID = UserID FROM dbo.Users 
WHERE UserName = 'MYDOMAIN\newuserhere'

UPDATE dbo.Subscriptions 
SET OwnerID = @NewUserID 
WHERE OwnerID = @OldUserID
Presto, your subscription has a new owner and will once again start running correctly.

UPDATE: I am going to try to work on something that will monitor the subscriptions and notify me if one of them fail.  Check back later.

Categories: Programming | Database | SQL Server
Tuesday, September 30, 2008 3:52:04 PM (Central Daylight Time, UTC-05:00) #    Comments [1]  | 

 

NHibernate Tutorials#

I have been poking around with NHibernate for a while now, but I am actually writing a small app with it at the moment.

During my time getting it up and running, I came across a few well written tutorials that I want to catalog here in case I want to return to them at some point for more in depth reading.

Great NHibernate Faq:
http://www.tobinharris.com/2007/2/3/nhibernate-faq

Fluent Interface for NHibernate:
http://blogs.hibernatingrhinos.com/...nhibernate.aspx

Alan Northam's Tutorials:
http://devlicio.us/blogs/alan_northam/...part-i.aspx
http://devlicio.us/blogs/alan_northam/...part-ii.aspx
http://devlicio.us/blogs/alan_northam/...part-iii.aspx
http://devlicio.us/blogs/alan_northam/...part-iv.aspx

 

Categories: Programming | .Net | Database
Tuesday, September 16, 2008 2:17:08 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Deploying Database Development#

Simple-talk.com has a pretty in depth article about deployment and mangement of databases.

Rolling out changes to the application is only 1 part of a deployment.  Updating the database can be more difficult depending on your schema.

We could have more process around the DB development and deployment process.  I will be giving this a read shortly.

Categories: Programming | Database
Wednesday, June 25, 2008 10:34:46 AM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

A connection that was expected to be kept alive was closed by the server#

Has anyone been getting these errors when serving up SQL Reporting Services Reports?

A connection that was expected to be kept alive was closed by the server

All of a sudden we have been getting a lot of these, and I am not sure at the moment what is causing them.

We have 2 webservers that are hosting the reportviewer control, which loads up reports from a single reporting server.

This guy suggested that this problem was related to some 10 minute timeout, but I haven't been able to replicate his 10 minute problem.

Some other people are talking about overrideing the webservice proxy classes to set KeepAlive = false, but we have no webservice proxy to override as we are using the reportviewer.

Update:

This guy is talking about changing the SSRS session timeout.

Could "rc:Toolbar=false" be the problem?

Update 2:
Looks like this was all caused by the introduction of an IDP by our network guys.

 

Categories: Programming | Database | SQL Server | Reporting
Monday, April 14, 2008 3:05:27 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Excluding weekends from a SQL date range#

Recently I wanted to find the time between 2 datetimes, but I wanted to exclude weekends.  To further complicate matters, I wanted to know hours, not just days.

The "standard" way to do stuff like this is to build out a calendar table that has every date for the next 50 years, along with info like "IsWeekend" or "IsHoliday".

But I found some snippets around that I hoped to use to my advantage, and what I came up with works very well:

DECLARE @start DATETIME
DECLARE @end DATETIME

SET @start = '3/7/08 12:50 pm'
SET @end = '3/11/08 1:50 am'

SELECT (DateDiff(hh, @start, @end) - DateDiff(ww, @start, @end)*2*24)/24.0
       
I won't spend a lot of time explaining why it works, but it basically counts the number of weekend "jumps" that are crossed between the 2 dates, and subtracts accordingly.

 

Categories: Programming | Database | SQL Server
Sunday, March 30, 2008 2:45:05 PM (Central Standard Time, UTC-06:00) #    Comments [3]  | 

 

Boilerplate TSQL Transaction Code for SQL Server 2005#

This is some useful stuff from 4guysfromrolla.com

BEGIN TRY
   BEGIN TRANSACTION    -- Start the transaction

   -- Your code here
-- If we reach here, success! COMMIT END TRY BEGIN CATCH -- Whoops, there was an error IF @@TRANCOUNT > 0 ROLLBACK -- Raise an error with the details of the exception DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int SELECT @ErrMsg = ERROR_MESSAGE(), @ErrSeverity = ERROR_SEVERITY() RAISERROR(@ErrMsg, @ErrSeverity, 1) END CATCH
Categories: Programming | Database | SQL Server | T-Sql
Thursday, March 13, 2008 3:50:01 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

SQL Server Reporting Services Email Subscriptions Not Going Out#

We recently ran into a problem with SSRS where our email subscriptions were processing, but no emails were going out.

SSRS doesn't really give you any info in the web interface to give you any clue that something isn't work right, let alone help you figure out what the problem is.

I was able to solve the problem by looking at the various log files that SSRS creates:  ReportServerWebApp__X, ReportServerService__X, and ReportServer__X.

In these config files I was able to find some errors coming back from our mail server. 

This lead me to discover that the problem was with how the email addresses were formatted. 

The issue was that we recently changed which mail server we used for sending out these emails, and we have moved from an Exchange 2003 server to an Exchange 2007 server.

Exchange 2003 would accept domain accounts as destinations for emails, so you could send an email to "cmay" and it would be delivered.  It seems that Exchange 2007 requires that you provide the full email address: cmay@company.com

After changing some of the SPs that served up the data, all worked once again.

 

Categories: Programming | Database | SQL Server | Reporting
Wednesday, March 05, 2008 4:18:38 PM (Central Standard Time, UTC-06:00) #    Comments [2]  | 

 

How To Strip Off the Time From DateTime (or Just Get The Date Portion)#

Every now and then I go to my blog to lookup something I wrote before only to find that I never posted it.

I would have bet someone $20 that I had posted something on how to strip off the time from a DateTime in SQL.  Why would you do this?

Well, lets say that have some autogenerated DateTime field (CreatedOn?) that you later want to join with another field, but the other field only knows the DATE when something happened, not the exact Date and Time.

So, you can use the following code to just get the DATE and zero out the time component:

SELECT CAST( CONVERT( CHAR(8), GetDate(), 112) AS DATETIME)

Categories: Database | SQL Server | T-Sql
Tuesday, November 27, 2007 2:59:44 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

SQL "NOT IN" Will Fail If The List Contains A Null#

If you are using the NOT IN clause with a SQL Select statement with SQL Server it will not work if there is a null value in the list.  Say for example you want to do:

SELECT * FROM 
Employees 
Where 
Employee.Id NOT IN 
(  
   Select EmployeeId from 
   Salaries 
   where Salary < 100000
)

If the inner select returns a null value then the outer select statement will return no rows.

To try it, just run these 2 SQL statments against any table in your DB.

-- will return rows
SELECT * FROM 
sometable
WHERE ID NOT IN (1,2,3)

-- will return nothing
SELECT * FROM 
sometable
WHERE ID NOT IN (1,2,3, null)
Categories: Programming | Database | SQL Server
Monday, October 29, 2007 12:02:18 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Dealing with null data in SSRS#

When working with a SSRS report, the report framework will already "Denull" everything.  But in some cases, for example when you are working with numbers, you might want to display a value in lue of the "" that is displayed for nulls.

Now you would THINK, that they would just use the same ISNULL syntax that everyone knows from sql programming.

HAHAHHAHA... of course they didn't do that.

Instead you have to use a combo of IIF and IsNothing like so:

=IIF(IsNothing(Fields!Quantity.Value),0,Fields!Quantity.Value)

It isn't THAT big of a pain, but I wish MS would sometimes just realize how much easier it would be for them to just create an IsNull function in their own codebase than make their users write this out.

Oh well.  I guess when it comes to problems with SSRS, this is waaaaaaayyyyy down my list.

Speaking of "my problems with SSRS"... when are you guys going to support TBLR text??  Drives me nuts.  Everyone does "vertical text" in TBLR format, for pretty much every application, but now in SSRS you are forced to use TBRL.  When you give these reports to engineers that is the very first thing they say "You need to turn this text around the other way".... yes I know, I got my degree in Civil Engineering with a focus on structure design, so when you come from a background of seeing all vertical text (like on any plans) as ALWAYS, by requirement, aligned in a TBLR manner, and then you are forced to cock your head the other way to read it, it is really a pain.

But I guess I would still like to see MS fix their *terrible* PDF rendering first.  I just LOVE watching my reports take 4x as long as in CR, and end up 100x bigger in file size than they are after being saved in acrobat (15 MB for a 1 page PDF, open in Acrobat, save the file again, down to 150KB, with no visible change in appearance or quality).

 

Categories: Programming | Database | SQL Server | Reporting
Thursday, September 27, 2007 10:22:45 AM (Central Daylight Time, UTC-05:00) #    Comments [1]  | 

 

Making a column non-null and unique in SQL Server 2005#
Someone asked me how to do this the other day, and I couldn't find a simple way to do it in the SQL Server Management Studio, but the script is pretty simple:

ALTER TABLE tablename
ALTER COLUMUN
   columnname varchar(50) NOT NULL
GO ALTER TABLE tablename ADD CONSTRAINT constraintname UNIQUE( columnname ) GO
Categories: Programming | Database | SQL Server
Thursday, June 28, 2007 8:10:19 AM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Moving changes from one table to another#

You just screwed up the database, and now you need to make some surgical repairs to the database.

Or maybe you have data in development and production tables and you want to move some data changes from one to the other.

Basically the problem is that you have 2 tables with the same schema where 1 column has some different values in one table when compared with the other.

You can't do an update on an inner join statement, but you can create an updatable view containing the fields you need and then run an update statement on it.

A view is updatable if it meets the following conditions:

A view is updatable if:

  • select_statement has no aggregate functions in the select list and does not contain the TOP, GROUP BY, UNION, or DISTINCT clauses. Aggregate functions can be used in a in a subquery in the FROM clause as long as the values returned by the functions are not modified. For more information, see Aggregate Functions.
  • select_statement has no derived columns in the select list. Derived columns are result set columns formed by anything other than a simple column expression, such as using functions or addition or subtraction operators.
  • The FROM clause in the select_statement references at least one table. select_statement must have more than nontabular expressions, which are expressions that are not derived from a table. For example, this view is not updatable:
CREATE VIEW NoTable AS 
 SELECT GETDATE() AS CurrentDate, 
 @@LANGUAGE AS CurrentLanguage, 
 CURRENT_USER AS CurrentUser 

Categories: Database | SQL Server
Tuesday, March 13, 2007 9:40:02 AM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Getting Just the Date Out Of GETDATE#

SQL Servers' GETDATE() function will return the current DateTime.  But what if you just want the current date.

CAST(FLOOR(CAST(GETDATE() AS float)) AS datetime)

or

CAST(CONVERT(VARCHAR(10), GETDATE(), 111) AS DATETIME)

See this page for even more options.

Or, if you want to get just the current time out of GETDATE or any datetime for that matter, check out this page (it is one of the FAQs).

 

Categories: Programming | Database | SQL Server
Sunday, March 04, 2007 10:36:17 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Avoiding @@IDENTITY#

When you are trying to get the last Identity value in SQL Server, the old way was to use the @@IDENTITY variable.

This, however, can easily give you the wrong answer back.  For example, if you have a trigger inserting a history record that also contains an identity column.

Here is an article that discusses why you should probably stick to SCOPE_IDENTITY().

Categories: Database | SQL Server | T-Sql
Sunday, February 11, 2007 11:04:08 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

ReportViewer with heigh=100%#

When you try to assign the web reportviewer control to a height of 100%, it displays as a very short (height wise) format.  For me, adding the style attributes to the form did the trick.

The solution to this problem was found on this page: http://msdn2.microsoft.com/en-us/library/ms252090.aspx.

Considerations for XHTML and ReportViewer Web Server Control

If you configure the ReportViewer Web server control to run in asynchronous mode in an application that is written in XHTML, you must follow specific steps to display the ReportViewer control properly. If the ReportViewer control uses relative height (for example, if the height is specified as a percentage of available space), the control collapses to a height of 0 pixels as a result of how frames and DIV tags render in containing tables in XHTML. You can avoid this problem by using one of the following workarounds:

  • Explicitly set the height on the on the ReportViewer control to an actual value rather than a percentage.

  • Add the following style setting to the head tag:

    <style>html,body,form {height:100%}</style>.

    By forcing the html, body and form tags to maximum height, the frame used in the ReportViewer control will also grow to maximum height, making it visible on the page.

  • Remove the xhtml doctype from the page.

Categories: Programming | Database | SQL Server | Reporting
Tuesday, October 24, 2006 3:27:04 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Getting the Access Default Menu Back#

I know Access is old news, but I have recently been asked to take a look at an old Access app.

This application replaces the existing menu at the top with a custom one, which really limits what you can do.

The solution to getting the menu back is to right click in the menu area, select customize, highlight "Menu Bar" and select properties, and change "Allow hide/show..." checkbox.  After you do this, you can then add it back into your form.

Categories: Programming | Database
Tuesday, October 03, 2006 3:47:04 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

"Updating" a SQL Inner Join Query#

I frequently get asked how you can update a join statement in SQL.  Of course, the UPDATE syntax doesn't allow for you do actually perform an update directly against a JOIN statement, but there are some things you can do to work around this problem.

Probably the best way is to do the update like the example below:

UPDATE Job_Opportunities
SET AwardedId = 1
WHERE JobOpportunityId = (
    SELECT JO.JobOpportunityId
    FROM Job_Opportunities JO
    INNER JOIN
    Job_results JobResults
    ON BO.JobOpportunityID = BR.Job_id
    AND JR.is_us = 1
    AND JR.rank = 1
    AND JO.JobOpportunityId = Job_Opportunities.JobOpportunityId
)

This example is updating the Job_Opportunities table, but in the WHERE clause we can use a join to make sure that the only rows that are updated are those that meet the criteria of the join.
Categories: Programming | Database
Wednesday, September 13, 2006 2:09:02 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

SQL Server Decimal/Money/Float datatypes#

When dealing with money, or numbers, sql server provides a few different datatypes: Decimal, Money, Float among others.

The main difference is that Decimal and Money datatypes are "exact", as opposed to Float which is a "Floating Point Representation".

When dealing with Floats, you can get some odd mathematical results:
http://www.chrismay.org/2005/09/29/BinaryRepresentationOfDecimalValues.aspx

e.g.
0.4 - 0.1 = 0.30000000000000000000004
1.4-1.1 = 0.29999999999999999999998

So when a number is going to represent money, you should use the Decimal or Money datatypes.  Money is (19,4) which means 19 total digits, 4 of which are right of the decimal point.  Decimal can be setup however you want, like Decimal(10,2).

SmallMoney can also be used, which can represent money values under 1,000,000 w/ 4 decimal places.

 

Categories: Programming | Database | SQL Server
Wednesday, September 06, 2006 9:40:48 AM (Central Daylight Time, UTC-05:00) #    Comments [1]  | 

 

SQL Server Merge Replication#

One of the challenges in doing merge replication in SQL Server is dealing with IDENTITY columns.

One of the tricks you can use is "automatic identity range management". 

Basically you tell DB 1 to start at seed 1 and DB 2 to seed at 20,000, and when DB 1 reaches 16,000 or DB 2 reaches 36,000 it will reset those seeds to 40,000 and 60,000.

http://msdn2.microsoft.com/en-us/library/ms152543.aspx

http://msdn2.microsoft.com/en-us/library/ms146907.aspx

It appears to work well.

Categories: Programming | Database | SQL Server
Tuesday, August 29, 2006 2:55:35 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Fixing up usernames after SQL Server Database Restore#

The problem is that if you restore a sql server database on a different computer than the backup was created, you can have the problem that the usernames and permissions are somewhat lost.

Each username has an associated SID.  So even though you might have a user named 'Bill' and the restore database might have a user named 'Bill', they will have different SIDs and so the permissions will not be applied to the correct user.

To fix this problem you can follow the following steps:

1) run this TSQL:

sp_change_users_login 'report'

2) This will produce a table showing you Users that having issues.

3) run the following TSQL:

sp_change_users_login 'update_one', 'UserNameFromStep2Table','NameOfUserToUse'

In many cases the 2nd and 3rd parameters will be the same string.

More about this SP can be found here: http://doc.ddart.net/mssql/sql70/sp_ca-cz_4.htm

 

Categories: Programming | Database | SQL Server | T-Sql
Thursday, May 25, 2006 4:20:46 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Grant Execute Rights To All SPs#

Many times you can have a database that has access to it restricted to SPs.  If the database is application specific, then there is a good chance that 1 user account will need to access all these SPs to run the application.

My friend Phil found and updated this script to run in SQL Server 2005 to generate the necessary code to grant execute rights to all SPs in a database for a given user.

SELECT 'GRANT EXECUTE ON ' + sysobjects.name + ' TO AccountName' + 

CHAR(10) + CHAR(13) + CHAR(10) + CHAR(13) 

FROM sysobjects 

WHERE type = 'P' and category = 0 AND name not like 'sp_%'

 

Categories: Database | SQL Server | T-Sql
Thursday, April 27, 2006 6:54:32 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

SQL Server Query Results To Excel#

There are many times when I just want to run a query and send the results to someone in an excel spreadsheet.

You can easliy copy the and past the results, but you don't get column headers, and you lose formatting in many cases.

Dinakar Nethi has a good article about how to directly import the results of a query into excel.

I just used his method and it worked great.

Categories: Database | SQL Server
Thursday, April 27, 2006 2:51:33 PM (Central Daylight Time, UTC-05:00) #    Comments [3]  | 

 

SQL Server's Stupid "Decimal" DataType#

Ok so, on a recent project, for some reason, I set up a few fields, and the corrosponding SP parameters as "decimal" datatypes. What a mistake.

After lots of rounding errors, which were partly ignored because the revised "specs" called for these figures to be integers (later changed to decimals), I found out that a Decimal datatype has no decimal places, unless you specifically declare it.

The reason for this is that a "decimal" is really just another name for a "numeric". So I guess I can understand that part... but how dumb is it that a decimal, by default, has no decimal places.

I went back and changed everything to float.

Use decimal(x,x) instead of float.  See here for the reason why.

Categories: Code Links | Programming | Database | SQL Server
Tuesday, September 27, 2005 9:42:13 AM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Microsoft TSQL Reference#
In case I haven't put this in here before.
Categories: Programming | Database | T-Sql
Wednesday, February 18, 2004 1:21:39 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

SQL Stress Test and SQL Server .NET CLR#
Here and here are 2 articles from SQL Junkies.

The first deals with the .NET CLR and it's role in the upcoming version of SQL Server, called Yukon.

The second talks about a tool that you can use to run a stress test on a SQL Servers disk setup.
Categories: Programming | .Net | .Net Framework | Database | T-Sql
Saturday, February 07, 2004 12:43:26 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Generating SQL SP Scripts In Order of Dependency#
This article discusses a way to generating a list of create scripts that are in order of dependency, so you don't get all those errors in the QA when you run the script.

Originally posted on 2/4/04, I should revisit this.
Categories: Programming | Database | T-Sql
Wednesday, February 04, 2004 10:21:02 AM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Dynamic SQL in SQL Server SPs#
Here is a pretty good white paper by a MSSQL MVP about using dynamic SQL in SPs.
Categories: Code Links | Programming | Database | T-Sql
Sunday, January 25, 2004 4:50:50 PM (Central Standard Time, UTC-06:00) #    Comments [0]  | 

 

Mobile Database Synchronization#
Categories: Programming | Database | Tools
Friday, September 26, 2003 5:51:20 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Add SQL Server 2000 Stored Procedures to Visual SourceSafe by Using Visual Studio .NET#
Categories: Programming | .Net | VS.Net | Database | T-Sql
Thursday, September 18, 2003 11:38:01 AM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

TSQL Reference#
Finally found this.

This link points to the getting started page. If you look down the tree on the left, you can see the TSQL Reference node.
Categories: Programming | Database | T-Sql
Monday, September 01, 2003 7:17:19 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Cleaner Calling of Stored Procedures#
SPInfoke is a tool that allows you to call SPs as static methods in a .NET class. I guess it won some awards and stuff, but I don't think (just from looking at the article) that is is nearly as good as the tools from Ellkey.com who's StoredProcToDotNet.htm wraps the SQLHelper classes in the MS Application Blocks for Data Access. They also offer a SP generator called the StoredProcBuilder.
Categories: Programming | .Net | Database | T-Sql | Tools
Thursday, July 03, 2003 12:37:21 PM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

Dynamic vs Static SQL#
Dynamic vs Static SQL
Categories: Code Links | Programming | T-Sql | Database
Tuesday, June 10, 2003 11:49:04 AM (Central Daylight Time, UTC-05:00) #    Comments [0]  | 

 

All content © 2010, Christopher May, Inc
Open Job Positions
On this page
Removing all extended properties from SQL Server
SQL NOT IN and NULL still will not work
Debugging SQL Server Deadlock Issues
Getting error reports when a SQL Reporting Subscription Fails
Finding if SP Parameters are Nullable
Avoid Overwriting Modified SPs With Code Generation
SQL Server encountered error 0x80070422 (FIXED)
Checking and Updating Identity Seed in SQL Server
SQL Reporting Services Subscription Ownership
NHibernate Tutorials
Deploying Database Development
A connection that was expected to be kept alive was closed by the server
Excluding weekends from a SQL date range
Boilerplate TSQL Transaction Code for SQL Server 2005
SQL Server Reporting Services Email Subscriptions Not Going Out
How To Strip Off the Time From DateTime (or Just Get The Date Portion)
SQL "NOT IN" Will Fail If The List Contains A Null
Dealing with null data in SSRS
Making a column non-null and unique in SQL Server 2005
Moving changes from one table to another
Getting Just the Date Out Of GETDATE
Avoiding @@IDENTITY
ReportViewer with heigh=100%
Getting the Access Default Menu Back
"Updating" a SQL Inner Join Query
SQL Server Decimal/Money/Float datatypes
SQL Server Merge Replication
Fixing up usernames after SQL Server Database Restore
Grant Execute Rights To All SPs
SQL Server Query Results To Excel
SQL Server's Stupid "Decimal" DataType
Microsoft TSQL Reference
SQL Stress Test and SQL Server .NET CLR
Generating SQL SP Scripts In Order of Dependency
Dynamic SQL in SQL Server SPs
Mobile Database Synchronization
Add SQL Server 2000 Stored Procedures to Visual SourceSafe by Using Visual Studio .NET
TSQL Reference
Cleaner Calling of Stored Procedures
Dynamic vs Static SQL
Google Ads
This site
Calendar
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 2.3.9074.18820

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: