Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Change Logical Filenames in SQL Server

I got a backup of a database from my co-worker, that i restored as "ABC" database.

It restored okay but when I check the logical named for both Data and Log file were "XYZ" and "XYZ_Log" respectively.

I just Googled for a solution and got a command to rename the logical files.

The command lines as below
    USE MASTER
    GO

    ALTER DATABASE DBName
    MODIFY FILE (NAME = ExistingLogicalDataFileName, NEWNAME='NewDataFileName')
    GO

    ALTER DATABASE DBName
    MODIFY FILE (NAME = ExistingLogicalLogFileName, NEWNAME=NewLogFileName)
    GO

If you want to visit the original article by Jon Galloway, click here



"The directory name is invalid." MSSQL Management Studio

I got an error when trying to modify a stored procedure

Searched for proper solution and found one EXCELLENT solution

Error :
Title - Microsoft Management Studio 2005
"The directory name is invalid."
 (mscorlib)

Solution:
As usual, the only solution to most of the issues in windows : Restarted the machine and error resolved :)




By

SQL Server 2005 Script to Generate INSERT statements


This procedure generates INSERT statements using existing data from the given tables and views. Later, you can use these INSERT statements to generate the data. It's very useful when you have to ship or package a database application. This procedure also comes in handy when you have to send sample data to your vendor or technical support provider for troubleshooting purposes. 

Click here to read original article and download script.

The same script can be downloaded from here

Is the above link useful to you? Let us know your feedback, it will help us to improve our posting(s). or You can send your feedback linkOblast.

CountBusinessDays


A good functions that everyone can use to Calculate Business Days between two dates.

Click here to view the original link


Excerpts:

Working with Access, I needed to calculate business days between
dates, excluding holidays, and with an eventual conversion fo the DB to
SQL Server, rewrote the VBA into an SQL function, below:


set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go


— =============================================

— Author: James Igoe

— Create date: 2008-08-29

— Description: Calculates business days between 2 dates

— =============================================

ALTER FUNCTION [dbo].[Fx_WorkdayCount]

(

@sStartDate As DATETIME,

@sEndDate As DATETIME

)

RETURNS SMALLINT

AS

BEGIN

— Declare the return variable here

DECLARE @BusinessDays SMALLINT


DECLARE @intDaysTotal As SMALLINT

DECLARE @intDaysWeeks As SMALLINT

DECLARE @intRemainder As SMALLINT

DECLARE @intRemainderPost As SMALLINT

DECLARE @intRemainderPre As SMALLINT


SET @intDaysTotal = DateDiff(day, @sEndDate, @sStartDate)

SET @intDaysWeeks = ((@intDaysTotal / 7) * 5)

SET @intRemainder = @intDaysTotal % 7


IF @intRemainderPre = 1

SET @intRemainder = @intRemainder - 1

ELSE IF @intRemainderPre = 7

SET @intRemainder = @intRemainder - 2


IF @intRemainderPost = 1

SET @intRemainder = @intRemainder - 1

ELSE IF @intRemainderPost = 7

SET @intRemainder = @intRemainder - 2


IF (@intRemainderPost < @intRemainderPre) And @intRemainderPre <> 7

SET @intRemainder = @intRemainder - 2


Dynamically Obtain a SQL Server’s IP Address in T-SQL Code

Do you want to obtain SQL Server IP address in your trigger or table?

Click here to get some knowledge on this topic.

Is the above link useful to you? Let us know your feedback, it will help us to improve our posting(s). or You can send your feedback to linkOblast.

Connection String

Developing database driven application and forgot text for connection string.....

dont worry !

To get sample for connection string for any database click here

or

here > http://www.connectionstrings.com/



Is the above link useful to you? Let us know your feedback, it will
help us to improve our posting(s). or You can send your feedback linkOblast.

SQL Server Reporting Service

Wanna usa SQL Server Reporting service ?

Visit the following site :


http://msdn.microsoft.com/SQL/default.aspx?pull=/msdnmag/issues/04/08/sqlserverreportingservices/default.aspx

SQL Server Performance

Want to Increases performance in SQL Server Performance, click the link

http://www.sql-server-performance.com/reviews.asp

SQL Formatter

Online SQL Format helps you to format your query with proper indent

http://www.wangz.net/gsqlparser/sqlpp/sqlformat.htm