sql-server-2008

SQL Query Time Coverage

I don´t now if this is the right place for such a question, but I´ll try it :) I have got several sql db entries which represents time periods E.G. Datefrom datetill 2010-10-01 2011-01-01 2011-02-01 2011-05-16 2011-08-08 2011-09-01 I need to test if a given time period ist fully covered from the entries. Is th...

database question

Hi, I have written a cursor like bellow : declare myCursor cursor for select productID, productName from products declare @productID int declare @productName nvarchar(50) open myCursor fetch next from myCursor into @productID,@productName print @productID print @productName set @productID=0 set @productName='' while @@FETCH_STATUS=0...

database question

Hi, I have written the bellow cursor : declare myCursor cursor for select productID, productName from products declare @productID int declare @productName nvarchar(50) open myCursor fetch next from myCursor into @productID,@productName print @productID print @productName set @productID=0 set @productName='' while @@FE...

Using LIKE in sp_executesql

Hi, SET @whereCond = @whereCond + ' AND name LIKE ''%'' + @name + ''%''' Is there something wrong here? After I generate where condition, I execute it with sp_executesql, but I did get anything. When I SELECT the same thing without sp, it's ok. How to use LIKE in sp_executesql? Can you bring some examples, please? Thank you. UPDA...

Convert PLSQL Cursor FOR Loop Syntax to TSQL

I have some PLSQL code which loops through some logic: FOR I in cur1 LOOP SELECT value1, value2 FROM db1..table1 t1 END LOOP; Can anyone explain to me the syntax for doing this in TSQL? ...

Counting groups of data in SQL

I have a table of about 1.6M rows where the records have a unique (identity) ID and then also have a 8-character "code" field. The code field it used to group data into sets...all rows with the same code are in the same set. Each set should consist of 12 records, but it seems our data load was off and some sets are incomplete. I need ...

Have one sproc that debugger won't step into (SQL Server 2008 Developer Edition on Win7x64)

I'm calling an sproc from SSMS, and that sproc calls a number of other ones. I can easily step through the outer sproc and, if I step-into, can walk through the sprocs being called. But one sproc simply won't be stepped into. Attempting to do so acts as if I stepped over it. That is, it runs without being stepped. There is nothing at al...

store arabic in SQL database

I tried to store Arabic string in SQL 2008 database but it converted to " question mark " why ? and what should I do ? ...

SQL Encrypted Columns in WHERE Clause

Hi I am looking to apply SQL column level encryption using symmetric keys. The initial steps needed to create the Database Master Key, Certificates and Symmetric Keys seems straight forward and I have tested encrypting/decrypting data using Symmetric Keys successfully. However, once the data is encrypted I don't know how best to query...

How to store both IPv4 or IPv6 in single column in SQL Server?

shall I use binary(16)? or varbinary(16)? I know I can use getAddress() in java.net.InetAddress (Java) or System.Net.IPAddress (C#) to get a byte[] representation of both IPv4 and IPv6, but if I need to insert IPv4 i.e. binary(4) into a binary(16) field in SQL Server, do I need to worry about padding or anything? Thanks ...

Handling Timeouts inside stored procedures

I have a stored procedure that executes a couple of queries. Each query might fail because of a timeout. I still want to continue to execute the other queries. Is this possible? Does a try catch work for timeouts? I can offcourse have different sps for each query, but that would make the application more complex. ...

SQL Server 2008, Powershell and Web Services

Hi, Powershell provides the New-WebServiceProxy cmdlet which allows for a web service proxy object to be created. However the Powershell in SQL Server 2008 doesn't appear to support this. Is there a way to get SQL Server's Powershell to support the New-WebServiceProxy cmdlet? Many thanks. ...

Intermittent slow query on SQL Server 2008

I am developing a system which periodically (4-5 times daily) runs a select statement, that normally takes less than 10 seconds but periodically has taken up to 40 minutes. The database is on Windows Server 2008 + SQL Server 2008 R2; both 64bit. There is a service on the machine running the database which polls the database and genera...

SQL Server 2008 100% CPU but not using a fraction of the memory it can

Suddenly our SQL server is using 100% CPU but only using a fraction of the memory it can use (16 GB available). We're using web edition and allocated a maximum amount of ram. Like i say this has just suddenly happened without us changing anything. Need some ideas desperately as it's crippling us ...

Cleaning up after calls to SMO Server and Database

Hi How do you make SMO release it's connections? I have this code: public static class SqlServerConnectionFactory { public static Server GetSmoServer() { using (var c = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString)) { var s = new ServerConnection(c)...

TableCardinality

Hi, in MS SQL 2010 What does it means TableCardinality in execution plan? I am looking at data base tuning performances Thanks ...

How to store sensitive information in SQL Server 2008?

I need to store some sensitive information in a table in SQL Server 2008. The data is a string and I do not want it to be in human readable format to anyone accessing the database. What I mean by sensitive information is, a database of dirty/foul words. I need to make sure that they are not floating around in tables and SQL files. At t...

Which approach is better for this scenario?

Hello SQL Gurus. We have the following table: CREATE TABLE [dbo].[CampaignCustomer]( [ID] [int] IDENTITY(1,1) NOT NULL, [CampaignID] [int] NOT NULL, [CustomerID] [int] NULL, [CouponCode] [nvarchar](20) NOT NULL, [CreatedDate] [datetime] NOT NULL, [ModifiedDate] [datetime] NULL, [Active] [bit] NOT NULL, CONST...

What's the difference between a SQL Server database FILE and an actual SQL Server database in ASP.NET?

Well, the subject heading essentially says it all: what's the difference between a SQL Server database file (.mdf) and an actual SQL Server database? Also, a couple of follow-up questions: Do database files exist for both SQL Server 2008 Express and SQL Server 2008 R2? Is there a difference between those if they do? When uploading a ...

Unique, Non-Required Column in SQL Server 2008

Using SQL Server 2008, I have a requirement that email addresses in my user table must be unique, but email addresses are not required in my app. I've tried to make email addresses required, but I just cannot get the customer to budge on this one. What is the best method to create this constraint? If I add a constraint, what does the con...