sql-server

Join two tables

How can i join these two queries SELECT GLMA_COMP_CODE COMP, GLMA_ACCT_CODE ACCOUNT_NO, GLMA_DEPT_NO DEPT, GLMA_ACCT_NAME ACCOUNT_NAME FROM GLAS_GL_MASTERS WHERE GLMA_COMP_CODE = @COMP_CODE AND GLMA_YEAR = CONVERT(NUMERIC(8, 2), DATEPART(YYYY, @DATE_FROM)) AND GLMA_ACCT_CODE BETWEEN ISNULL(@ACCT_CODE_FROM, GLMA_ACCT_CODE) AND ISNULL(...

Can I use DataTables to import data from one database into another?

I need to create a quick and dirty solution to migrate data from database into another. This is only being used a proof of concept. Long term we will use .NET's Sync Framework. The databases are identical. The solution is going to be used as an OCA (occasionally connected application). I read in which tables they want to migrate fro...

SQL Server Profiler: How can I display query parameter values in deadlock graph?

Hi, I'm trying to debug a deadlock with SQL Server Profiler 2008. I know how to get a graph of the deadlock in the profiler, but when I hover over one of the two statements in shown in the graph, the "Statement" tooltip that appears only contains the query with parameter names, not values. In other words I get tooltips like this: DE...

Parameter passing Vs Table Valued Parameters Vs XML to SQL 2008 from .Net Application

As We are working on a asp .net project there three ways one can update data into database when there are multiple rows updation / insertion required Let's assume we need to update employee education detail (which could be 1,3,5 or 10 records) Method to Update Data Pass value as parameter (Traditional approach), If 10 records are the...

Clear all the rows in a table resetting the identity specification back to zero and without affecting the foreign keys?

We have already created the database framework, with all the relations and dependencies. But inside the tables were just the dummy data, and we need to get rid of these dummy data, and start adding the correct ones. How can we clear everything and leave the primary keys (IsIdentity: yes) back to zero, and also without affecting the forei...

does connections count matter?

We have an application that uses NHibernate to connect to our database on SQL Server.We use connection pooling and session per request approach to execute our queries over SQL Server. We used SQL Server Activity Monitor to monitor connections count and noticed there was 25-30 connections involved whenever a user logged in to system. So h...

Get first or second values from a comma separated value in SQL

I have a column that stores data like (42,12). Now I want to fetch 42 or 12 (two different select queries). I have searched and found some similar but much more complex scenarios. Is there any easy way of doing it? I am using MSSQL Server 2005. Given there will always be only two values and they will be integer ...

when did SQL Server get uniqueidentifiers as a datatype?

Who remembers when Microsoft Sql Server got UniqueIdentifier as a data type. I'm guessing it was 7.0 but maybe it was as early as 6.5? ...

How to get column which has least values among them

CREATE TABLE exmp_test ( id int, v1 int, v2 int, v3 int, v4 int ) SELECT * FROM exmp_test id v1 v2 v3 v4 1 2 4 6 7 1 4 77 3 8 I want to add the value of the [id] column to (whichever has least value for v1 ,v2 ,v3 ,v4) for each row. As an example, for the first row, the [id] value should be add to v1 (because it ...

How do I get parameter values for SQL Server query in SQL Server Profiler

Hi, I'm trying to analyze a deadlock in SQL Server 2008 profiler. I know how to find the offending sql queries, but the collected queries do not include parameter values. I other words I can see something like this: DELETE FROM users WHERE id = @id But what I would like to see is this: DELETE FROM users WHERE id = 12345 I guess...

Connecting to remote SQL Server 2008 from Windows Azure

I am trying to connect to a SQL Server 2008 instance from a Windows Azure worker role (it's not SQL Azure, but a remotely hosted SQL Server 2008 Standard Edition), but I get the following error message System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server....

Sql Server index statistics

Does the following seem normal for a histogram on an index? Histogram Steps RANGE_HI_KEY RANGE_ROWS EQ_ROWS DISTINCT_RANGE_ROWS AVG_RANGE_ROWS 2264548 0 1 0 1 2302473 36550 1 36550 1 2303523 767 1 767 1 2383218 77051 1...

Using select fields in other computed fields in SQL Server

I have a table with columns A, B and C, and I want to select from that table, but with some additional fields computed from A, B and C and other computed fields. For example: D = A * B + C E = 2 * D + 4 * A F = D * D * E I thought I could solve that like this: select A, B, C, (A * B + C) as D, (2 * D + 4 * A) as E, (D * D * E) as F ...

how to open sdf (sql server compact edition) file?

I have an SDF file and I would like to retrieve its schema and query it with some UI. How can I do this? I have no Visual Studio installed on the machine and I would like to install as little software as possible. ...

rsExecutionNotFound error in SQL Server Reporting Services

I have a SQL Server Reporting Services 2005 installation that has worked great for a few years now, but has been giving me occasional glitches recently. I'm using the default reporting services website instead of embedding reports into my application, which has proven a very efficient way to deploy the reports. The OS is Windows Server...

Convert String to Date

I try to convert a string into a date in t-sql. However get results that I can't explain. DECLARE @String as char(11) DECLARE @TString as char(11) SELECT @String = SUBSTRING([Flat File Source Error Output Column],1,CHARINDEX(',',[Flat File Source Error Output Column])-6) FROM [ERROR].[Import_V2X] SELECT @TString = '12/18/2009' -- Che...

SQL Server 2005 Replication Not for Replication Attribute

I work for a company that has 32 locations, each location having its own SQL server. Replication is set up from each location to a central location, and then from the central location to a main office location. The main office location also has data that is entered, which replicates from the main office to the central location, and the...

Check date interval with SQL Server

Hi in a stored procedure I want to select rows that are in an interval of a month where @Anno is the year of the start and @Mese is the month of the date start. I try this: WHERE FinePeriodo >= CAST((@Anno + '-' + @Mese + '-01 00:00:00') as datetime) AND FinePeriodo < DATEADD(month, 10, CAST( (@Anno + '-' ...

Read XML from Sproc and Write to File

I need to read a large xml result (using For XML) from a stored proc and write it to a file in a .Net app. My first shot is to read the xml from the proc using XmlReader. I then need to write it to a file. Is this best way to handle this scenario, or is there a "better" method? ...

How do I connect to my 64-bit SQL Server with ODBC?

I recently installed SQL Server 2008 Express on my Windows 7 Ultimate x64 home machine. I also have IIS 7.5 with PHP 5.3, and I was trying to connect to SQL via ADODB, but kept getting this error: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application After doing a small...