SQL Server does not have Trim() function. So we can create a own UDF (User Defined Function) function for this since SQL Sever does LTRIM(),RTRIM() functions and we can use this any time. Here I have created a simple Function for this. Create Function Trim(@mText varchar(MAX)) Returns varchar(MAX) AS Begin return LTRIM(RTRIM(@mText)) End You can run this function as shown below here, Select dbo.Trim(' Test ') So this function would return ‘Test’ only as LTRIM() function would cut off the Left side spaces and RTRIM() functiom would cut off the Right side spaces.
1.create the Database with same Name,MDF Name,LDF Name. 2.Stop the Sql Server and then Replace the only new MDF file by old database (Corrupted database) MDF file and delete the LDF File of newly created database. 3.Now Start the Sql Server again. 4.you can notice that database status became 'Suspect' as expected. 5.Then run the given script to know the current status of your newly created datatbase. (Better you note it down the current status) SELECT * FROM sysdatabases WHERE name = 'yourDB' 6.Normally sql server would not allow you update anything in the system database.SO run the given script to enable the update to system database. sp_CONFIGURE 'allow updates', 1 RECONFIGURE WITH OVERRIDE 7.After run the above script, update the status of your newly database as shown below. once you updated the status, database status become 'Emergency/Suspect'. UPDATE sysdatabases SET status = 32768 WHERE name = 'yourDB' 8.Restart SQL Server (This is must, i...
Stored procedures are stored in SQL Server databases. The simplest implication of stored procedures is to save complicated queries to the database and call them by name, so that users won’t have to enter the SQL statements more once. As you see, stored procedures have many more applications, and you can even use them to build business rules into the database. How to create a Stored Procedure, As shown given below, created a Stored Procedure for Inserting records into Table call Holiday_Details, which has Code and Description fields. In this Stored Procedure, passing two parametrs as INPUT Parameters and one OUTPUT parameter. Normally in Stored Procedure we can pass parameters as Input / Output Stored parameters. When you define output parameters, we have to implicitly specify the OUTPUT Keyword. Here I have shown the simple stored procedure. CREATE PROCEDURE [dbo].[SP_Holiday] @Code char(3), @Desc varchar(100), @flag bit, @Err Varchar(MAX)=Null OUTPUT AS Begin Transaction if @flag=0...
Comments
Post a Comment