sql-server

SQL Server: GROUP BY Aggregation semantics with the PIVOT operator

I am on SQL Server 2008 and I have a table containing WA metrics of the following form : CREATE TABLE #VistitorStat ( datelow datetime, datehigh datetime, name varchar(255), cnt int ) Two days worth of data in the table looks like so: 2009-07-25 00:00:00.000 2009-07-26 00:00:00.000 New Visitor 221 2009-07-25 00:00:00.000...

How To Speed Up Loading DataSets

When Using SQL Server Reporting Services (client Reports), whenever a Client (rdlc) report Opens Visual Studio Loads entire application datasets, how to speedup loading this all datasets or how to change the process to only load specific Dataset to use in Report ? ...

cannot connect to local server

i have sql server 2005 installed in my local machine. when i installed it, i was able to connect to the local server which is named "MNTCON016". After restarting the machine, I found out that i was not able to connect to the local server "MNTCON016". it gave me the following error. A network related or instance specified error occured wh...

SQL Trigger that runs ONLY at Publisher

I have an in house app that has both a Web Interface and a Desktop Interface(is an OCA using Merge Replication). We are still using SQL 2005 and have many 'Archive' tables set up. These are filled by Triggers on there relating Table. tblPersonArchive for tblPerson, etc. To keep the Replication Sets as small as possible I would like t...

How to configure SSIS 2005 OLE DB data source component to use sql query from external file?

I am using OLE DB data source component as a part of data flow task, but I would like to keep the sql query in an external file and not embedded in the task itself. Is there an easy way to accomplish this? ...

SQL Server Query Execution flow

I am looking for information about how SQL Server actually handles query execution in finer details (like what data is kept in buffer/memory and how does it decide to get fresh data even if there is an update change in only one column of a table involved in a query etc) If anyone knows sources please let me know? We have an web appli...

Why not "Invalid column name XYZ" error in subquery; although column name is not in subquery table?

When I run this query SELECT CustomerId FROM Stocks.dbo.Suppliers It gives me this error. Invalid column name 'CustomerId'. This error is valid as there is no column CustomerId in Suppliers table; but when I use same query in subquery it does not give any error E.g. SELECT * FROM SomeOtherDb.dbo.Customer WHERE CustomerId In( SEL...

SQL to find first non-numeric character in a string

I inherited a table with identifiers in a format [nonnumericprefix][number]. For example (ABC123; R2D2456778; etc). I was wondering if there was a good way to split this in SQL into two fields, the largest integer formed from the right side, and the prefix, for example (ABC, 123; R2D, 2456778; etc). I know I can do this with a cursor,...

SQL Server: Select in vs or?

Which is faster? SELECT UserName FROM dbo.UserTable WHERE UserID in (1,3,4) SELECT UserName FROM dbo.UserTable WHERE UserID = 1 OR UserID = 3 OR UserID = 4 ...

mssql_query doesn't return anything

I am having problems with setting up a system. We have a SQL Server 2005 running and I want to connect it from another windows machine running php 5.2 and apache. I can connect to SQL using mssql_connect but I can not retrieve any results from a simple query (SELECT * FROM USERS) mssql_query doesnt return anything nor dies or shows an ...

Created a new database on SQL Server, can't be seen by web apps because permissions aren't set.

So I created a new database on my SQL Server box and then added an ODBC entry so my ASP code knows what it is. Now I am getting this error: Cannot open database "DB_NAME" requested by the login. The login failed. I checked out the permissions by right clicking the db in Management Studio and checked permissions and low and behold it i...

SQL Server Exception: "The column name xxx is not valid" when using JDBC

I'm getting a strange error from the SQL Server JDBC driver. It is telling me that a column name is invalid even though the column is present, correctly named and the same query works fine when executed in SqlServer Management Studio. The error is: Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The column name MarginCall i...

How to detect open database connection with Hibernate / JPA?

I am learning JPA w/Hibernate using a Java SE 6 project. I'd simply like to be able to detect if the connection between Hibernate and my database (MS SQL Server) is open. For example, I'd like to be able to detect this, log it, and try reconnecting again in 60 seconds. This is what I thought would work but isOpen() doesn't appear to be ...

SQL table variable

Hi there. Here is my simple question: I want to declare a table variable with different columns according to the value of a predefined variable The query is as below: if (@a = 1) begin declare @table_1 table ( col1 int, col2 int, col3 int ) end else begin declare @table_1 table ( col1 int, ...

Replace SQL Server Database

A vendor has a data database (read only) that gets sent to us via dvd every week. Their upgrade script detaches the existing copy of the database, overwrites the MDF and LDF, drops all the users and recreates what they think proper security should be. Is there a way that I can just synchornize the data without taking the database offli...

Join tables SQL Server

I want to join two tables but I want the result set to only show matches that arent in the right side. Example: LeftTable leftID | PK value | RightTable rightID |PK leftID |FK select l.value from LeftTable l join RightTable r on l.leftID = r.leftID I know this wont give me what I want, but I am just trying to find o...

Reporting Services - Get the results for a specific period through a longer period

Hello, I have a table that retrieves data over a 3 day period on an hourly basis, there are several different machines that work on a specific bottle for a period of time, during the three day period there could be several different bottles go on that machine. I want to show the results of the 1st bottle during the time that they were ...

Basic Database design. Use a another table or colum

I have a table that holds information about a particular Object, Say Item and has columns ItemID, ItemName, price, ItemListingType.....LastOrderDate One of the bits of information, ItemListingType could be one of 10 different types such as: private, gov, non-gov, business... etc (strings) and could be extended to more types in future....

Need steps for Alter the table

Whenever I make changes to a table structure in SSMS, there is a alert raised: saving the changes is not permitted.the changes u have been made to the following tables to be dropped and recreate.. ...

Finding duplicate rows in SQL Server

I have a SQL Server database of organizations, and there are many duplicate rows. I want to run a select statement to grab all of these and the amount of dupes, but also return the ids that are associated with each organization. A statement like: SELECT orgName, COUNT(*) AS dupes FROM organizations GROUP BY orgName ...