sql-server

Sending a summary of SQL Server Agent job failures

SQL Server Agent allows you to create Notifications at the moment a Job succeeds or fails, but I'd like to create a regular notification that sends a summary of the events for those who are one step removed from server maintenance. Is there a way to setup summary notifications that spell out which jobs failed over the last 24 hours? ...

Creating Sequence in Sql Server

I want to create a sequence of numbers in sql server it will have the minimum value and maximum value, i want to cycle if the number reaches the maximum limit. Can any body help me?? ...

SQL Server 2000 T-SQL: writing to MSMQ?

Is there a way to write to MSMQ from T-SQL and/or Stored procedure? I am using SQL Server 2000. ...

How to create a link in an iif condition in reporting services

I want to create a link in a condition in reporting services. i have something like iif(SomeField = "Canceled",SomeFiled,SomeField & link) So the output would be: Completed Download Report (with link to report) But if i put html code like: <a href="somelink">Somelink</a> It just spits out the html code, and no link is cr...

SQL Server slow select from large table

Hello, I have a table with about 20+ million records. Structure is like: EventId UNIQUEIDENTIFIER SourceUserId UNIQUEIDENTIFIER DestinationUserId UNIQUEIDENTIFIER CreatedAt DATETIME TypeId INT MetaId INT Table is receiving about 100k+ records each day. I have indexes on each column except MetaId, as it is not used in 'where' clause...

MySQL to SQL Server transferring data

I need to convert data that already exists in a MySQL database, to a SQL Server database. The caveat here is that the old database was poorly designed, but the new one is in a proper 3N form. Does any one have any tips on how to go about doing this? I have SSMS 2005. Can I use this to connect to the MySQL DB and create a DTS? O...

Is it possible to host SQL server in the cloud and connect an ASP.NET app hosted on DiscountASP?

Does anyone know if it's possible to host a SQL server in the cloud and connect an ASP.NET app hosted on DiscountASP? I'd like to consolidate my SQL Server instances but keep the web app hosting where it's at. There are various reasons for I want to do this and I don't particularly want to get into it. I don't have any experience wit...

SQL Server Session State causing Serialization error

I have an .Net 3x application using default WCF serialization and recently setup application to use SQL Server Session state and am not being able to store those objects in session state with sql server, only in proc session state. Getting errors on various classes stating: Unable to serialize the session state. In 'StateServer' and 'S...

How to include SqlExpresss 2008 (conveniently)

When I make a setup project in VS 2008, and select <Setup Project>, Properties, PreRequisites then i can select SqlExpress2005 to be automatically included. What I am looking for is a walkthrough of how to get SqlExpress2008 included in the same manner. Second choice would be how to get (or make) a MergeModule (MSM) file to do the sa...

Is it possible to retrieve the raw SQL which returned an error in SQL Server?

I've got a SQL Server 2005 database and a classic ASP front end (don't ask). I'm trying to debug some errors in the IIS log file (error code 80040e14), and I'm not having much joy at the ASP end of things. Is it possible to retrieve the raw SQL which caused the error from SQL Server directly, or failing that set SQL Server to record such...

SQL Server Select and Update in the same statement?

Hello! I have an SQL Query like this: SELECT TOP (@TopType) AdvertID, IsAdvertImage, AdvertData FROM Adverts WHERE AdvertSize = @AdvertSize ORDER BY NEWID() Each row in the table Adverts also has a column called Views, is it possible to also increase views with 1 for the banners that has been fetched? So I set TopType to 4 and get 4 ...

Are delimited identifiers considered a "best-practice" in Transact-SQL?

I'm working on some legacy SQL and the author delimited every column name and data type declaration. See the following: CREATE TABLE SomeTable ( [SomeDate] [datetime] NOT NULL, [SomeInt] [int] NOT NULL, [SomeString] [nvarchar] NOT NULL ) ON [PRIMARY] GO Is this considered a best-practice when writing T-SQL for S...

WCF and SQL Server: changes in DB are displayed only after app restarts

I'm developing a client-server app using WCF and Linq2Sql. My server-side program exposes to the clent an interface that provides methods of reading from and writing to my SQL Server DB. But when the client writes some date into DB, perhabs waites some time, and then tries to read that data from DB, it seems like no data has been written...

How do I insert the identity ID column in XML data in a SQL Server table?

I have an audit table in my SQL Server 2008 database which contains the XML for data that I am auditing. Inside this XML, though, I require the ID of the audit record in the audit table. The catch is that the ID is an identity column. So it is kind of a catch 22, I can't insert the XML until I know the ID, and I cant find the ID until...

Can't log in to SQL Server 2008 Management Studio

Hello, I think something happened to an mdf file on disk. When I try to start SQL Server Mgmt Studio (SQL Server 2008, Win 7 x64), I get an error: "Cannot open user default database." Since I can't connect at all, how do I fix this? I have tried connecting to other dbs using osql, but always get an error. Thanks for any workarounds... ...

SQL statement merging/simplifying

Hi, I'm not sure whether my SQL code and practise here is any good, so hopefully someone could enlighten me. In order to try and separate my DAL from the Business layer, I'm not using an SQLDataSource on the page. Instead, I've created a gridview to display the results and called an SQL command to retrieve results. I have the followin...

CTE error: "Types don't match between the anchor and the recursive part"

I am executing ;with cte as ( select 1 as rn, 'name1' as nm union all select rn+1,nm = 'name' + CAST((rn+1) as varchar(255)) from cte a where rn<10) select * from cte and is receiving the error Msg 240, Level 16, State 1, Line 2 Types don't match between the anchor and the recursive part in column "nm" of recursive query "cte". Wh...

How to disable CDC for a table manually?

I dropped a table before disabling CDC for that. Now when I recreated the table and tried enabling CDC it says that capture instance already exists. I can use a different Capture Instance name but need to know if there is anyway to drop the associated capture instance manually. When I delete a table through SSMS GUI it drops CDC tables...

Create a global static variable in SQL Server?

Is there a way to create a global variable in SQL Server so it's saved even the server is shut down, so I can use it in functions? Example from what I need: DECLARE @@DefaultValue bit This variable should never be deleted unless I explicityl do so. ...

SQL server SP : @Param 's with sometime NULL values

I am very new to SQL Server Stored Procedures, I am trying to create a SP that will give return a list of records in a table by filter via StartDate and EndDate , but there will be 'View All' Option so sometime those @Param might not contain any values. Currently my SP is Like CREATE PROCEDURE [dbo].[spGetBonusRun] ( @StartDate as DA...