.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

SQL Server 2005 Stored Procedures

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :Sql Server
  I had written a stored proc. to get date & time in Std. format  dd/mm/yy hh:mm:ss AM/PM. I wanted that  when no value is given to the stored procedure it should produce current date & time in the above std. format & when some date is given , it should display that date in above std. format. The stored proc. is as follows: set  ANSI_NULLS ON set  QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[GETDATETIME] @DATE DATETIME = NULL, @NEWDATE VARCHAR(MAX) OUTPUT AS BEGIN --DECLARE @TEMPDATE DATETIME; --SET @TEMPDATE=NULL; --SET @TEMPDATE=; IF (@DATE IS NULL) BEGIN SET @DATE=GETDATE(); SET @DATE=CONVERT(DATETIME,CONVERT(VARCHAR(MAX),@DATE,3)+ ' ' + CONVERT(VARCHAR(MAX),@DATE,24)) ; SET @NEWDATE = convert(varchar(MAX),@DATE, 103)+' ' + CONVERT(VARCHAR(MAX),SUBSTRING(CONVERT(varchar(MAX),@DATE,22),10,12)); GOTO L1; END SET @DATE=CONVERT(DATETIME,CONVERT(VARCHAR(MAX),@DATE,3)+ ' ' + CONVERT(VARCHAR(MAX),@DATE,24)) ; SET @NEWDATE = convert(varchar(MAX),@DATE, 103)+' ' + CONVERT(VARCHAR(MAX),SUBSTRING(CONVERT(varchar(MAX),@DATE,22),10,12)); -- Declare the return variable here --DECLARE @Result int -- Add the T-SQL statements to compute the return value here --SELECT @Result = @p1 -- Return the result of the function --SET @NEWDATE2=CONVERT(VARCHAR(MAX),@NEWDATE); L1: RETURN CONVERT(VARCHAR(MAX),@N

View Complete Post

More Related Resource Links

SQL Server 2005 Express Edition - GUI to set permissions on stored procedures

Hi there, I have SQL Serve 2005 Express Edition (Build 2600: Service Pack 3) installed; I also have the Management Console installed. My problem is that I cannot set execute permission, or any other type of permissions on my stored procedures through the GUI, as the Property menu item is missing from the right click menu. I read somewhere that this happens when you have SP1, but as I stated above I have got SP3 installed... Any help?   Regards, D.

CLR stored procedures asssemblies working in sql server 2005 but giving issues over sql server 2008

Hi I developed CLR stored procedures assemblies using VS2005 and deployed in sql server 2005 are working fine. Currently we are migrating to sql server 2008. The same CLR assemblies are not working in 2008 version and raising following error. Here i created CLR assemblies in sql server 2008 using 'sa' user account which is having db_owner permission over 'mydatabase'. I am getting an error message like "A .NET Framework error occurred during execution of user-defined routine or aggregate". In sql logs showing messages like as -- Common language runtime (CLR) functionality initialized using CLR version v2.0.50727 from C:\Windows\Microsoft.NET\Framework\v2.0.50727\. -- AppDomain 2 (mydatabase.dbo[runtime].1) created.   Please let me know what may be the cause for this type of issues. Is there any specific backward compatibility settings has to be done over sql server 2008 or sql server 2008 R2 while using 2005 CLR routines?   Thanks in advance.  

sql server 2005 view rights only on stored procedures



 I would like my developers to be able to view stored prcedures in production but not execute or modify them.  Is there a way to do this?  I tried granting view definition to the schema but I think they can still modify the procedure.  Any ideas?




Howto use Visual Studo 2008 to maintain SQL Server 2005 tables and stored procedures


I I have an ASP.Net web site I built using Visual Studio 2008.  I also have a SQL 2005 database I use with this web site.  I presently use MS SQL Server MManagement Studio Express to add / modify SQL tables, stored procedures, etc. 

But I want to now maintain my SQL datbase directly from my Visual Studo 2008 where I maintain my ASP,Net web site.  I have created a script from my QL DB that creates all my existing tables and stored procedures.  Can I somehow run this to create the necessary source files within VS 2008?


Folders or folder like equivalent in SQL Server 2008 ? for packages & stored procedures ?

Hi,      Currently running SQL-Server 2000.  We have hundreds of stored procedures and DTS packages. We have so many it's becoming a serious challenge for names and such.  We were wondering if SQL Server 2008 has a way to 'nest' both the equivalent of DTS packages (SSIS) and stored procedures in something akin to 'folders'.  We know we have to upgrade one of these days but a version that would handle these would be much more attractive. Just getting this functionality would be worth whatever effort would be required to upgrade.   Thanks in advance for any help on this.

Stored procedures not found in Analysis Server

Hi, it seems that my AS2008R2 installation got corrupted and I don't find any way to repair it. AS doesn't "find" stored procedures. Nor stored procedures written by me, nor system stored procedures, nor Data Mining stored procedures. E.g., when I try to browse a Data Mining model I get the following error: Query (1, 6) The '[System].[Microsoft].[AnalysisServices].[System].[DataMining].[AssociationRules].[GetStatistics]' function does not exist. The problem started with my AS2008 installation. I unistalled, then re-installed. Then I upgraded to AS2008R2. Then I repaired the AS2008R2 installation. Nothing ! I don't want to reinstall the server. Please help ! Thanks          Teodoro Marinucci

SQL Server 2005 - Specifying Optional Parameter in Stored Procedure

I need to alter the following stored procedure so that the UserID is an optional parameter. I have, as yet, been unsuccessful. Basically, if the user doesn't supply a User ID, I want to return all of the users that match the other criteria.

This seems like it should be a simple thing.......


@CompanyID tinyint

,@DepartmentID tinyint

,@ApplicationID int

,@UserID AS









FROM [ReportQueries]


[UserID] = @UserID

how to create stored procedure in sql server 2005 and how to use that stored procedure in asp.net


Hi friends ,

       I am very newbie

I have created stored procedure and student database and also asp.net application for asp.net page

but it could not found stored procedure what is the mistake actually I don't no

Please help me

Warm Regards


Restoring sql server database with stored procedures



I have a database that needs restoring to get a website up and running.  I am not a ASP developer (am PHP) and therefore have never used SQL Server before.

I have just tried to import one of the tables from a .txt file using SQL Server Management Studio 8 and instead of the column names being inputed, it just has "column 0", "column 1" etc.  I have noticed that I have a folder full of stored procedures, am I supposed to import these first?  Im not 100% what these stored procedures are for or the best way for me to import all this data successfully as I have so many files it will take forever to import one by one.  I dont mind doing it one by one if I have to but just want to ensure I do it all correctly first time!

Many thanks

CRUD Stored Procedure Code/Scripts Generator for SQL SERVER 2005


I need a simple anf functionally CRUD Stored Procedure Code/Scripts Generator.

Anyone have a solution?

Thanks in Advance.

Unable to execute system stored procedures - SQL Server 2000, SP4

I am unable to execute system stored procedures on a SQL Server 2000 server, running Windows 2003, SP1. If I try to run sp_updatestat I recieve a 2758 error after it updates a few tables. If I run sp_recompile, it returns the same error. If I run DBCC CHECKDB on the master database, it reruns a blank screen. Database and T-Log dumps work without issue. This started all of a sudden. I have restarted SQL as well as rebooted the server. Everything came up clean. Need advice desperately.
Steve Jimmo

Unable to execute system stored procedures - SQL Server 2000, SP4

I have a SQL Server 2000, SP 4 running on a Windows 2003 server with SP1. All of a sudden I am unable to execute system stored procedures. When I try to run sp_updatestats 'RESAMPLE' it will update the stats of a couple of tables and then return a 2758 error. I have tried to run DBCC CHECKDB on the master database which returns a blank screen. Database and transaction log dumps are working without an issue. Everything on all other databases works without a problem. I have restarted SQL Server as well as rebooted the server. Everything comes up clean. Cannot find anything on this type of problem and am desperate.

Issues with CLR Stored Procedures - SQL Server 2008


Dear members,

I really hope that someone will be able to help me.

I'm trying to create an assembly in sql 2008, for a dll i've created in c# (net 3.5 frameword).

The dll is calling a WS method, that will do some calculations.

The issues i'm having is, once I try to create the assembly, it tells me "

Msg 10301, Level 16, State 1, Line 1

Assembly 'XYZ' references assembly 'system.runtime.serialization, version=, culture=neutral, publickeytoken=b77a5c561934e089.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(failed to retrieve text for this error. Reason: 15105)). Please load the referenced assembly into the current database and retry your request.


" , which I do understand, and following this message, I am trying to create assembly, for the System.Runtim.Serialization dll.

But, if i try to create the dll, it tells me the following:


Warning: The Microsoft .NET Framework assembly 'system.runtime.serialization, version=, culture=neutral, publickeytoken=b77a5c561934e089, process

SQL Server 2005 Grant User Permission to Create Stored Procedure and Grant Execute Access to another


I'm trying to determine the minimal amount of access I can give my developers to be able to run create stored procedure scripts with an inclusion of the grant execute to the application user group.

We have been developing some interesting work arounds, but I think there must be an easier way to grant the access.

Grant Create Stored Procedure to user1 on a specific database

Grant Permission to Grant Execute permission for Stored Procedures on a specific Database to user1 for any user.


SSRS 2008 Server Exployer not displaying all stored procedures from the database


When I look in the Server Exployer I don't see any of the recently stored procedures that have been developed on the database.  Is there a setting I need to make to be able to see my new stored procedure?

SQL Server 2005 Transactional Replication Fails to Publish Stored Procedure Containing an Index Crea


I've experienced a bizarre problem with a SQL Server 2005 Transactional Publication. The issue is this: If the publication contains an article that is a stored procedure that contains a create index statement, then there is an error thrown when attempting to replicate the schema of the stored procedure to a subscriber.

The behavior is very odd, because even if the create index statement is commented out, it still gives the exception, and it will only work if it is removed altogether.

Here is the exact error that's being returned:

Command attempted: GRANT EXECUTE ON [dbo].[usp_Test] TO [CompanyDatabase_access]

(Transaction sequence number: 0x00000170000008B9000500000000, Command ID: 5)

Error messages: Cannot find the object 'usp_Test', because it does not exist or you do not have permission. (Source: MSSQLServer, Error number: 15151) Get help: http://help/15151 Cannot find the object 'usp_Test', because it does not exist or you do not have permission. (Source: MSSQLServer, Error number: 15151) Get help: http://help/15151

The error is accurate, because when I check on the subscriber, the stored procedure wasn't created as expected... but that was the purpose of the publication...

Calling stored procedure from funciton in sql server 2005


Is there any way to call stored procedure from funciton in sql server 2005?

If it is possible, please give some examples.



RAHUL Dot Net Developer
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend