sql-server

In SQL server is there any way to get the 'use database' command to accept a variable

I would like to write a 'generic' script to operate on a number of databases. The 'use databasename' commands will be distributed in the body of the script. I would rather show the database name information at the top of the script. So ideally: declare @db varchar(100) set @db = 'data_in' use @db This fails. So perhaps declare @db ...

Save XLSM file to Database column and retrieve ?

The code previously implemented takes in the xls file saves it on to a column in a table using the stream i use the same method but the only change is the the file saved is a xlsm or an xlsx type file it saves to the column in the database When I try and get the contents from the database and throw the saved xlsm file or xlsx file I get...

Why are my SQL indexes being ignored?

We're having a problem where indexes on our tables are being ignored and SQL Server 2000 is performing table scans instead. We can force the use of indexes by using the WITH (INDEX=<index_name>) clause but would prefer not to have to do this. As a developer I'm very familiar with SQL Server when writing T-SQL, but profiling and perform...

SQLServerCE / Local Data Cache / Sync Framework - Insert Error

Hi, Hopefully someone can help me. I have a Visual Studio 2008 WinForms application to which I have added a Local Data Cache. The local data cache is using a SDF file via SqlServerCE and is caching a SQL Server 2008 dbase with change tracking enabled. This is working and I can do bidirectional syncs and the like. The problem I am ...

How to protect a database from the Server Administrator in Sql Server

We have a requirement from a client to protect the database our application uses, even from their local administrators (Auditors just gave them that requirement). In their requirement, protecting the data means that the Sql Server admin cannot read, nor modify sensitive data stored in tables. We could do that with Encryption in Sql Ser...

Sql query Monthly result but how?

This query returns me first below table. forexample; 2009-06-01 00:00:00 people enter my system '41' times. i need second table declare @date1 smalldatetime, @date2 smalldatetime , @countgap int, @page nvarchar(100) select @date1='2009-01-01', @date2='2009-12-30 23:59:59' ,@countgap=1, @page='Tüm Sayfalar' declare @@date1 smalldate...

MS SQL Update within a loop

Hi, im trying to realize something like this: DECLARE @id int declare @cont varchar(max) declare @temp varchar(max) DECLARE curs CURSOR FOR SELECT id, [content] FROM [dbo].[Contents] OPEN curs FETCH NEXT FROM curs into @id, @cont WHILE @@FETCH_STATUS = 0 BEGIN SET @temp = replace(@cont, @param_ReplaceThis, @param_WithReplace...

SQL Server: Search all tables for a particular GUID

i came across the need to cleanse some data, and i need to find some particular guids (i.e. uniqueidentifiers) in SQL Server°. i've come up with a stored procedure that does a SELECT from every uniqueidentifier column in every table in the current database, and returns a result set if the guid is found. It uses the INFORMATION_SCHEMA v...

SQL 2005 SSRS Report Manager changes

How can the Report Manager interface be changed to view only from the gray bar right below the four tabs, view, properties, history and subscription? ...

when were index statistics last updated?

Is there a quick and easy way to list when every index in the database last had their statistics updated? The preferred answer would be a query. Also, is it possible to determine the "quality" of the statistics: FULLSCAN, SAMPLE n, etc. EDIT this worked for what I needed, a slight mod to @OrbMan great answer... SELECT STATS_DATE(...

Adding rowguid column broke this Stored Procedure?

I have added a bounty to this as I have, as yet been able to figure this out and time is out. The below stored procedure will not allow me to add it to Modify it. When attempting to modify it I get the following error --> Msg 213, Level 16, State 1, Procedure spPersonRelationshipAddOpposing, Line 51 Insert Error: Column name or n...

Is there a simple way to Copy SQL Server 2000 DTS package and deploy it in another server?

I am trying to copy a database from one server to another in id different location, including all the schema, data, DTS Package and Scheduled Jobs. I used Redgates SQL Packager to pack the schema and data.But I am having trouble in packing the DTS Package (which is a very complex one) in simpler way.Please advice! ...

Using "GO" within a transaction

I'm building a web app that attempts to install/upgrade the database on App_Start. Part of the installation procedure is to ensure that the database has the asp.net features installed. For this I am using the System.Web.Management.SqlServices object. My intention is to do all the database work within an SQL transaction and if any of it ...

Referencing a 3rd Party class library within a SQL Clr Class

I am creating a SQL CLR assembly that needs to use a Third Party assembly inside it. The trouble is I cannot reference this assembly as only ones already deployed to SQL or other SQL project references are allowed. Is it possible to use 3rd party assemblies in a SQL CLR assembly and if so how? Thanks in advance. ...

loopback detection

I have a Master File table on a server(A). Data is first replicated to a central server(B) and then to all of our locations(C). Then from C->B->A A = Sql 2005 B = SQL 2005 C = Sql 2000 My issue is that data gets all the way to C but replication is set for updates yet I get a Primary Constraint error from C -> B. I set loopback detect...

How to 'thin' a database table out?

I have a large DB table which I am using for testing. It contains 7.3m phone call records. I would like to delete many of those, but still maintain a good spread over phone numbers and dates. Is there any way of achieving this? Maybe something to do with table sample? ...

How to order project solution content in SQL Server Management Studio

In SQL Server Management Studio (SSMS) running against SQL Server 2005, I have a solution which contains a number of views. These views are not sorted alphabetically. Can anyone provide either an explanation of why, or a solution to order them alphabetically ? ...

Implicit conversion from varchar to Varbinary how to?

I got the following error trying to convert from a varchar to varbinary.. Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query. and this is the alter command that I tried. alter table foo Alter column bar varBINARY(max) So how do I use the convert function...

LIMIT 10..20 in sqlserver

I'm trying to do something like : SELECT * FROM table LIMIT 10,20 or SELECT * FROM table LIMIT 10 OFFSET 10 but using SQLServer The only solution I found looks like overkill: SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY name) as row FROM sys.databases ) a WHERE row > 5 and row <= 10 I also found: SELECT TOP 10 * ...

Can I use SQL Server Management Studio Express to connect to an MSDE database?

Is it possible to use SQL Server Management Studio Express 2005 to connect to an MSDE database? ...