sql-server

How to help QA team access the right database?

In the place I work, very often it happens that a developer and QA session goes like this: (This is in reference to SQL Server 2005) QA: I get Invalid object name 'customers' DEV: huh? can u send me the exact SQL statement you used? QA: select * from customers DEV: hmm. (after some thinks) Are you sure you're using CUSTDB? QA: yes DEV: ...

How to write a .Net application that works with both SqlServer and Oracle (now that System.Data.OracleClient is deprecated)

see also System.Data.OracleClient namespace discontinued? (Firstly don’t panic yet, System.Data.OracleClient is not being removed by Microsoft yet, however it is not in the client version of .net 4) This use to be possible by using System.Data.OracleClient, however Microsoft has decided to deprecate OracleClient. (OracleClient is the ...

insert int into xml column sql

How do i go about insert an int parameter into a xml modify insert statement here is am example: DECLARE @holdxml xml DECLARE @myInt xml set @myInt = 10 SET @holdxml = (SELECT CAST(VehicleManufacturerXML as xml) FROM VehicleManufacturers WHERE VehicleManufacturerID = 496); SET @holdxml.modify('insert <VehicleManufacturerID>cast(@myIn...

How to send Mail through data base Using sql server 2005?

Dear All , i want to develop an application where need to set reminder and send mail through database on particular time duration. ...

Using temporary table in where clause

I want to delete many rows with the same set of field values in some (6) tables. I could do this by deleting the result of one subquery in every table (Solution 1), which would be redundant, because the subquery would be the same every time; so I want to store the result of the subquery in a temporary table and delete the value of each r...

How do I obtain information about a nullable foreign key from Information_Schema views?

I'm using the INFORMATION_SCHEMA views in Sql Server 2005 & 2008 to obtain metadata for a database: SELECT PK.TABLE_NAME as 'PK_TABLE_NAME', FK.TABLE_NAME as 'FK_TABLE_NAME', C.CONSTRAINT_NAME as 'CONSTRAINT_NAME' FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONS...

A strange sql bug (multipart identifier) about sql server

I encounter a strange bug - multpart identifier "tableabc..fielda" cannot be bound today. In the above sql, I accidentally add one more dot in the query. I key in 2 dots in the sql query. It works in the development server (mssql 2005). When it comes to staging server (also mssql 2005), the above error occurs. What's the cause of that...

regEx to transform tsql Insert on Update command

I'm not very skilled with regex, I was wondering if it was possible to use a regular expression to transform a string like insert into tblTest (id,title,col1,col2) values (1,'test','test1','test2') into update tblTest set title='test',col1='test1',col2='test2' where id=1 btw, the insert query will not be always like the one I've wr...

How to use Linq To Sql to count the idle working duration in a day?

For example, I have a Task MIS, the data is: Id User Task TaskStartTime TaskFinishTime 1 Mike task1 2009-07-28 09:00:00 2009-07-28 09:45:00 2 Mike task2 2009-07-28 09:30:00 2009-07-28 09:40:00 3 Mike task3 2009-07-28 09:50:00 2009-07-2...

Is it possible to update parentID as part of a move opperation without using temporary columns?

The problem I have is that I have an old database where there typicaly are a lot of tables with internal parent/child relationship. These tables are getting migrated to a newer data structure, but we want to keep the old relationship. Today I do this as follow: Old table is tbl_contract. PK: contract_pk, FK: contract_parent_id, contrac...

Datatype not supported in SQL Server 2008 while creating trigger

Which Datatypes are not supported in SQL Server 2008 while creating trigger ...

howto use bcp_bind to insert dateTime values in sql server (2008) ?

Hi, I've a sample table, and it has cols of a few types including datetime. I'm trying to test bulk insert into it using the bcp_* api. I encounter a problem when trying to insert datetime values into the DB (error msgs include 'invalid date time format' when I try to insert as text or 'numeric value out of range' when trying to use ...

Connect remote SQLServer Database programmatically using VPN

Hey Ya'll, I can connect to VPN and I can access Sql Server using RDP. Now, I want to access the Sql Server programmatically. I connected to the VPN and then have the following connection string set up: **constr = 'Data Source=servername;Initial Catalog=dbname;User ID=username;Password=passwd;' error: login failed for username PS: ...

Cause of SSIS Custom Dataflow Component Error - Cannot be upgraded

I have a very simple component which trims all leading and trailing spaces from (read/write) strings in a pipeline. As far as I can see, I only have one binary of this dll on my development machine. I am transferring it to another development machine and registering it in the GAC, but when I open a package I copied to the second machin...

sql server avg_user_impact

In the DMV sys.dm_db_missing_index_group_stats, there is a field named avg_user_impact. Per BOL, this shows the Average percentage benefit that user queries could experience if this missing index group was implemented. The value means that the query cost would on average drop by this percentage if this missing index group was implem...

Starting and stopping a named instance of SQL server 2005 from a client computer

The issue I'm running into is that I don't always have access to the server but I need to restart the database on the server. Is this possible if so how would I do this? I know you can start and stop a named instance from cmd from the server. Not sure how to do from client. ...

ADO.NET Whitespace padding problem

Hi all, I've switched from LINQ to SQL to ADO.NET (with MSSQL) because of a problem I described earlier, but I also ran into a weird problem using ADO.NET. I import data from an excel worksheet using excel interop and I place its contents to the database. I trim everything that gets inserted, so this is not (supposed to be) the source ...

Order of (nolock) and table aliases on SQL Server

So I've got a SQL statement that pared down looks something like this: SELECT column FROM table t (nolock) LEFT OUTER JOIN table2 (nolock) t2 on t.id = t2.id This statement works on my SQL 2005 and SQL 2008 environments. It does not on a remote SQL 2005 environment. I've switched the last line to: LEFT OUTER JOIN table2 t2 (nolock) o...

Use APPLY with an UPDATE statement as the row source

I tried to perform the following in order to update a psuedo-identity value at the same time as using the value to create new rows, but APPLY does not like UPDATE statements as the right table source. What's the most elegant alternative outside of simply using an identity column? create table Temp1( id int not null identity(1,1) pr...

SQL query join elements

Hi guys. I will re-write my doubt to be more easy to understand. I have one table named SeqNumbers that have only one collumn of data named PossibleNumbers, that has value from 1 to 10.000. Then I have another Table named Terminals and one of the collumns have the serial numbers of the terminals. What I want is get all the SerialNumbers ...