Showing posts with label microsoft. Show all posts
Showing posts with label microsoft. Show all posts

Monday, August 10, 2009

SQL Server SP Parameter Default Value

SQL Server does not allow creating a stored procedure with parameter default values that are not constant. This can be a problem if you want to give a parameter a default value that is predictable but not constant such as giving a datetime parameter a default value of the current time.

There are two ways to resolve this. One is solution but it's not very flexible. The other is a workaround but can be used in more situations. First the solution. If the parameter is used as a minimum or maximum value check, you can totally ignore the value if it's null.

Here is an example of the first solution. Let's say we want to write a stored procedure to get all records from an Activity table that occured from one point in time to another. In this case we want to include all records if the boundry variable is not specified. In the example below we simply do this by checking for NULL and using the logical OR.


CREATE PROCEDURE GetActivityRecords
@From DATETIME
@TO DATETIME

AS
 BEGIN
   SELECT * FROM Activity
   WHERE (@From is null or LogTime >= @From)
   and (@To is null or LogTime <= @To)
 END


Another way to do this that is more flexible is to check if the parameter is null and in that case set it equal to whatever value you wish.

For example, in the code below I check if the @To variable is null and if it is I set it equal to the current time.


CREATE PROCEDURE GetActivityRecords
@From DATETIME
@TO DATETIME

AS
 BEGIN
   IF @To is null
   BEGIN
      SET @To = GetDate()
   END

   SELECT * FROM Activity
   WHERE (@From is null or LogTime >= @From)
   and LogTime <= @To
 END

Wednesday, April 9, 2008

Microsoft Office Sharepoint Server Resources


I was looking online for Sharepoint information and training material and here are some excellent resources I found:


Free Sharepoint 2007 Server Courses by Microsoft
http://office.microsoft.com/en-us/training/CR102146081033.aspx
Some of these course are very basic and are meant for general users not developers. For example, some of them teach the user how to upload or save a file directly from Word/Excel/Powerpoint to a Sharepoint server.



Sharepoint desktop training download.
http://www.microsoft.com/downloads/details.aspx?FamilyId=7BB3A2A3-6A9F-49F4-84E8-FF3FB71046DF&displaylang=en



Sharepoint standalone and server training download
http://office.microsoft.com/en-us/sharepointserver/HA102488011033.aspx



Sharepoing server home page
http://office.microsoft.com/en-us/sharepointserver/default.aspx



Sharepoint 2007 Server help page
http://office.microsoft.com/en-us/sharepointserver/FX101211721033.aspx



Sharepoint Server 2007 Virtual PC Harddrive Image
http://www.microsoft.com/downloads/details.aspx?FamilyID=67f93dcb-ada8-4db5-a47b-df17e14b2c74&DisplayLang=en
This image runs a Windows Server 2003 R2 Enterprise Edition machine. The virtual machine is for evaluation purposes and will expire after 30 days. You can login to the image using the following creditentials:
Username: Administrator
Password: pass@word1



Sharepoint Server 2007 Virtual PC Harddrive Image with Instructions and Walkthrough
https://connect.microsoft.com/Downloads/DownloadDetails.aspx?SiteID=428&DownloadID=7004
This image has been expired but can still be used for an hour each time the virtual machine is started.



Let me know if you find this of help.