sql-server

SQL Server 2005 - Pivoting Data without a sum / count and dynamic list of values

Sorry if this is covered elsewhere in another question, but I can't find any examples which exactly match what I need and I'm getting confused. I have data in the table like this :- Name | Value --------------- John | Dog John | Cat John | Fish Bob | Python Bob | Camel And I would like the data like this.......

How to quickly edit values in table in SQL Server Management Studio?

Aside from context menu -> "Edit Top 200 Rows" from Object Explorer, is there a quick way to open a table in Edit mode where I can just quickly modify the value of a cell? I need to be able to page past the first 200 rows. And I dont want to write "insert" script for every minor tweak I need to do... I don't understand why SMS doesn't...

import .bak file to a database in sql server

hi, i have a file with .bak extension. how can i import this date to a database in SQL Server. is any one have an idea.please share it with me. thanks ...

Sql Server double subquery

I have a table which is kinda like an historic table... so I have data like this idA numberMov FinalDate 1 10 20090209 2 14 20090304 1 12 20090304 3 54 20080508 4 42 20090510 ... ... .... I need to retrieve the numberMov based on the newest finalDate from each ...

Executing queries with ExecuteWithResults using the BatchSeparator

We are using Smo.Server to run some SQL batches. For queries that create stored procedures or tables and contain the separator GO the following code works: server.ConnectionContext.ExecuteNonQuery(sql); But the following fails server.ConnectionContext.ExecuteWithResults(sql); For sql that doesn't change the database structure it se...

Is nHibernate intended to replace database objects?

I've not yet found a clear answer to this and to clarify: With nHibernate and SQL server are you expected to disregard or migrate your business logic stored in your stored procedures, views and triggers into HQL or application code? ...

Why exactly are non-DB related functions in SQL Server so much slower?

I always hear that non-DB related functions (e.g. string comparison, loops) in SQL Server are slow because, well, it's a database. But why exactly does that fact make these methods crawl in comparison to full programming languages? ...

Sql Server 2005 Returns Results From Some Other SP

I have a data access layer which returns DataSets/DataTables by executing Stored Procedure. Everything was working fine from many months. But suddenly we have started getting the following error. System.ArgumentException; Column < ColumnName > does not belong to table < TableName > I wrote come extra logging code to troubleshoot this i...

Issue calling a MySQL stored procedure (with params) via a linked server (SQL Server 2005) using OPENQUERY syntax

Hello, I'm having issues when trying to call a MySQL (5.0.77) stored procedure with parameters, via a linked server (SQL Server 2005) using the OPENQUERY syntax. The MySQL stored procedure returns a result set, and when I use the 'EXEC ... AT ...' syntax the call works fine, e.g... EXEC('CALL my_stored_proc(''2009-10-07'',''2009-10-07...

How can I transfer LINQ to SQL results to an external dll?

Before LINQ I would have my main application return the results of a SQL query into a dataSet. I would then transfer the dataset as a parameter to the external dll. Now I am bringing through a LINQ to SQL query that is returned as an IQueryable(Of vClientTable) object. I want to be able to transfer that set of vClientTable results to my ...

Value should be 0 between the two dates?

Using SQL Server 2000 I want to compare the table2.date between table1.from, table1.todate, if exist then value should be 0 (zero) Table1 ID FromDate ToDate 001 20090801 20090815 002 20090817 20090820 …, Table2 Id Date Value 001 20090730 100 001 20090731 200 001 20090801 300 001 20090802 400 … 001 20090815 0 001 20090816 250 … ...

Why does creating a table with a foreign key constraint in one transaction block access to the referenced table in another?

In one transaction I am creating a table which references another table. In a second transaction, I run a SELECT-query against the referenced table but it is blocked by the first transaction. Why is that? Transaction A: BEGIN TRAN CREATE TABLE Child (id int NOT NULL, parentId int NOT NULL REFERENCES Parent (id)); ...

Many-to-many relationship structure in SQL Server

Assume that we have two tables: Roles and Reports. And there exists a many-to-many relationship between them. Of course, the only solution that comes to my mind is to create a cross-table, let's name it RoleReport. I can see two approaches to the structure of that table: 1. Columns: RoleReportId, RoleId, ReportId PK: RoleReportId 2....

Merging 2 SQL Queries

I've got 2 queries I'd like to merge into 1 result set without using union. Query 1 select datepart(yy,dateclosed)as 'Year', datepart(mm,dateclosed) as 'Month', count(*)as 'Total' from bug where projectid = 44 and ifclosed = 1 and isnull(createdbyperson,1) <> '-1111111110' and datepart(yy,dateclosed) > '2000' group by datep...

% in the beginning of like clause

I heard that its not advised to use % in the beginning of LIKE clause in SQL Server due to performance reasons.Why is this is so? Some more details on this will help me in understanding the impact of this issue. ...

Update field based on value of another field in the same table

This is a big problem for me and it seems like it is too simple to be discussing this, however I may be over-complicating it. It's in SQL. Here is my situation, I have a table called Monthly_Hierarchy as follows: SITENUM LOCATION_ID FRANCHISE 1101 5522005 R 1101 5522005 F 1102 ...

Python multiprocessing and database access with pyodbc "is not safe"?

The Problem: I am getting the following traceback and don't understand what it means or how to fix it: Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main self = load(from_parent) File "C:\Python26\lib\pickle.py", line 1370, in load r...

Does the Order By clause recalculate the value in SQL Server?

When I use a calculation or a subquery in my ORDER clause which is already in my SELECT clause, does SQL know to just order by that column? Or does it recalculate everything for each row when sorting? For instance, lets say I'm writing a terrible query like this: SELECT EmployeeName, (SELECT COUNT(*) FROM Employee e2 WHERE MgrID = Empl...

Enterprise Library Data Access Block Transaction Management Best Practice

What is the best practice for processing a batched series of CRUD operations in a single transaction with the Enterprise Library Data Access Block that it won't be esclated to a distributed transaction? Edit Full Source: public void BatchInsertEvents(IList<EventItem> events) { _dataAccessBase = new DataAccessBase("[dbo].[EventInser...

Sql Query Group a range of numbers with low's and high's

Hi all, I have a table that looks something like below street_id | address_number | address_direction | address_street | address_type ... ---------------------------------------------------------------------------------- 1 | 121 | W | Fake | St 1 | 131 | W ...