sql-server

Visual Studio References: Specific Version setting question

I have a Winform App that we uses internally that I publish through ClickOnce with SQL Express 2005. The app also references a couple of Microsoft.SqlServer dll's. I am trying to figure out how the Specific Version settings work. I have SQL 2008 installed on my machine they have 2005. If I select Specific Version = false will it ca...

Why does "SELECT DISTINCT a, b FROM..." return fewer records than "SELECT DISTINCT A + '|' + B FROM..." ?

I have a query that's selecting a bunch of fields related to names and addresses of customers but it boils down to: SELECT DISTINCT a, b, c, ... FROM big_dumb_flat_table it returns a bunch of records (10986590). When I replace the commas in the select-list to format it as a pipe-separated concatenated string: SELECT DISTINCT a + '|'...

How update Stored Procedure has Optional Parameter?

How can I alter Update Stored Procedure so if developer want to set only Size then he/she does not requireed to pass TimeStamp. Moreover, then what will be execute code for this procedure? Scenario: Update TimeStamp = getdate() field whose SizeID = 1 AND Size =Large Note: This field Parameters and condition parameters must be dynamic ...

Appropriate query and indexes for a logging table in SQL

Assume a table named 'log', there are huge records in it. The application usually retrieves data by simple SQL: SELECT * FROM log WHERE logLevel=2 AND (creationData BETWEEN ? AND ?) logLevel and creationData have indexes, but the number of records makes it take longer to retrieve data. How do we fix this? ...

SQL: Expanding a row with start/end into individual rows

Hello I have a records like this: start, end , total 830 , 1300, 5 1400, 1430, 2 that I'd like to expand to: instance , total 830 , 5 831 , 5 832 , 5 ... 1299 , 5 1300 , 5 1400 , 2 1401 , 2 ... 1429 , 2 1430 , 2 How can I do this using SQL in MSSQL 2005? EDIT...

SQL group by clause understanding (simple question / SQL server 2005)

HI all, I'm having some difficulty understanding the rationale behind group by aggregation in sql server 2005. I have the following query which works fine and returns one row for each contact.id and the 1st occurence of event SELECT contact.id ,MIN(eve.date_created) FROM _contact contact WITH(nolock) INNER JOIN table2 tb2 WITH (nolock)...

Checking if something has changed in a trigger

I have a need to monitor a subset of fields on a table and perform a task when one of them changes. I am using a trigger on the table update which and then am looking at the changes as follows: -- join the deleted and inserted to get a full list of rows select * into #tmp from (select * from inserted union select * from deleted) un -- ...

One-to-one relationship or One-to-many?

Maybe I need more coffee this morning but here goes... I have a very simple inventory system. Right now I have two tables: Items and Inventory. Items Id Title YearReleased Inventory Id ItemId(Foreign key to Items) Quantity QuantityOnHand Each item has one inventory and each inventory belongs to one item. The relationship betwe...

mssql '5(Access is denied.)' error during restoring database

hello, i want to restore database from file(Tasks->Restore->Database. atrer i select from device and select file) via sql server management studio. After that i get this error: The operating system returned the error '5(Access is denied.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'E:\Program Files\Microsoft SQL...

SQL Server Performance of Parameterized Queries with leading wildcards

I have a SQL 2008 R2 Database with about 2 million rows in one of the tables and am struggling with the performance of a specific query when using parameterized SQL. In the table, there's a field containing a name in it: [PatientsName] nvarchar NULL, There's also a simple index on the field: CREATE NONCLUSTERED INDEX [IX_Study_...

How do I find a disabled index on SQL server 2008

A while back when I was performing some bulk inserts of data into my SQL Server database, I disabled a number of indexes to improve the insert performance. I now need to go back and rebuild/re-enable them. Unfortunately, I'm not sure exactly which indexes I disabled. Is there a way I can query to identify which indexes are disabled an...

DDL statements with variables for table and column names

In my stored procedure, I make a temp_tbl and want to add several columns in a cursor or while loop. All works fine the cursor (the creation of a temp_bl but I can´t add the column when the column string is in a varchar variable. WHILE @@FETCH_STATUS = 0 BEGIN SET @webadressenrow = 'Webadresse_'+CAST(@counter as nchar(10)) A...

Pulling facebook and twitter status updates into a SQL database via Coldfusion Page

Hello All, I'd like to set up a coldfusion page that will pull the status updates from my own facebook account and twitter accounts and put them in a SQL database along with their timestamps. Whenever I run this page it should only grab information after the most recent time stamp it already has within the database. I'm hoping this wo...

Where do SQL Server Management Studio queries actually execute?

If I am using SQL Server Management Studio on my local machine to execute a query which is manipulating data on one or more remote servers, where does the actual computing take place? Is it using my local resources or that of the remote server? ...

SQL Server Mangament Studio 2008 unable to connect to SSIS packages on SQL Server 2005

I get an "Class not registered" error whenever I attempt to connect to the integration services on sql server 2005 from within SQL Managment Studio 2008. Is there a workaround? or do I have to downgrade to SQL managment studio 2005? ...

SQL Server Error: "%" is not a constraint. Could not drop constraint. See previous errors.

I'm using Microsoft SQL Server 2005, and am relatively new to SQL in general. There is a relationship between two tables, "Resources" and "Group_Resources", in the database "Information". Resources has a foreign key, "id", in Group_Resources, named "resource_id". There is a foreign key constraint, "fk_gr_res_resources", between the tw...

Storing binary objects in SQL Server with LINQ

I'm trying to do the same thing as in this question, but am having problems. Can you share with me how you prepared your objects prior to inserting and updating the database? I have a List<myObject> that I want to store as a VarBinary(max) in SQL Server 2008. ...

SQL select statement dynamical multiple conditon

I have 3 tables, say images(id), news(id), types(id, category, obj_id, type) For example, categories of news A are black, red. data struct is like { types(xxxx1,red,news_A,news) types(xxxx2,black,news_A,news) } now I need find out all images with type red and black. In this case, I need images_B { types(oooo1,red,images_B,i...

SQL Server Select Question

I have a query, say Select foo from bar Foo is a string field, and will always start with "http://". I want to replace "http://" with "xml://" during the select, so all foo values come back as xml://..., instead of http://... Is there a way to substitute on the fly, during the query? ...

Having trouble with a SQL report for Dynamics CRM

I am trying to create a statement like report for invoices, I have it so far that it displays the invoice and the amount due and also the payment if it has been paid, I have all this in a table with the invoice on 1 line and the payments on another with them grouped. What i really what to achieve is to have them ordered by date and for i...