sql-server-2005

SQL Server 2005-pivot

Pivot: Assume that you have table A that contains data regarding tips earned for each employee in the following format: A(empid, Mon_tips, Tues_tips, Wed_tips, Thu_tips, Fri_tips). Write a SQL query that will convert the data from table A into table B with the following format: B(empid, Day, tips) where the column Day can take the value...

convert xml file to sql server 2005 table?

how to convert a xml file in to sql server 2005 table?can any one help me? do we have any query to convert xml file to sql server 2005 table ...

Moving from a non-clustered PK to a clustered PK in SQL 2005

HI all, I recently asked this question in another thread, but was told it would be better to move it to a new question instead. What if I have an auto-increment INT as my non-clustered primary key, and there are about 15 foreign keys defined to it ? (snide comment about original designer being braindead in the original :) ) This...

Files and filegroups sql server 2005

Can we move default file to another filegroup. sample code is given below Sample code create database EMPLOYEE ON PRIMARY ( NAME = 'PRIMARY_01', FILENAME = 'C:\METADATA\PRIM01.MDF', SIZE = 5 MB , MAXSIZE =50 MB, FILEGROWTH = 2 MB), ( NAME = 'SECONDARY_02', FILENAME = 'C:\METADATA\SEC02.NDF' ), FILEGROUP EMPLOYEE_dETAILS ( NAME = 'EMP...

A table that has relation to itself issue

Hi , I've defined table with this schema : CREATE TABLE [dbo].[Codings]( [Id] [int] IDENTITY(1,1) NOT NULL, [ParentId] [int] NULL, [CodeId] [int] NOT NULL, [Title] [nvarchar](50) COLLATE Arabic_CI_AI NOT NULL, CONSTRAINT [PK_Codings] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON ...

Component Properties window - only three things can be seen rather than 20+

Hi All, Trying to edit an SSIS package, when I go to the advanced editor on the update database package I can only see on the component properties page three properties. ID, Name and Description. when my colleague opens this up he can see 20+ options including the SQL option I am needing to be able to edit. Is this an issue with my SQ...

Optimzing TSQL code

My job is the maintain one application which heavy use SQL server (MSSQL2005). Until now middle server stores TSQL codes in XML and send dynamic TSQL queries without using stored procs. As I am able change those XML queries I want to migrate most of my queries to stored procs. Question is folowing: Most of my queries have same Where con...

SQL Query to get largest datatype in schema

What is the query to get the top 5 ...data types ...used in a DB by size? blob > int ...

How to shred an xml input parameter into a table variable

Hello, I am accepting an input parameter of xml type so that i can accept a list of insurance plans on a transaction. I need to take the xml parameter and shred it into a tale variable so that i can process some logic. How can i shred the XML into my table variable. Here's a script to create a sample table with data in it; /* CREATE T...

How to fix incorrect syntax near 'LOGIN' in SQL Server 2005

ALTER USER [myuser] WITH LOGIN =[myuser] This query returns error in one of the SQL Server 2005 SP1 installation. Error is Incorrect syntax near 'LOGIN' ...

SQL 2005 indexed queries slower than unindexed queries

Adding a seemingly perfectly index is having an unexpectedly adverse affect on a query performance... -- [Data] has a predictable structure and a simple clustered index of the primary key: ALTER TABLE [dbo].[Data] ADD PRIMARY KEY CLUSTERED ( [ID] ) -- Joins on itself looking for a certain kind of "overlapping" records SELECT DISTINCT ...

How can I pivot these key+values rows into a table of complete entries?

Maybe I demand too much from SQL but I feel like this should be possible. I start with a list of key-value pairs, like this: '0:First, 1:Second, 2:Third, 3:Fourth' etc. I can split this up pretty easily with a two-step parse that gets me a table like: EntryNumber PairNumber Item 0 0 0 1 0 ...

Weird SQL Server 2005 Collation difference between varchar() and nvarchar()

Can someone please explain this: SELECT CASE WHEN CAST('iX' AS nvarchar(20)) > CAST('-X' AS nvarchar(20)) THEN 1 ELSE 0 END, CASE WHEN CAST('iX' AS varchar(20)) > CAST('-X' AS varchar(20)) THEN 1 ELSE 0 END Results: 0 1 SELECT CASE WHEN CAST('i' AS nvarchar(20)) > CAST('-' AS nvarchar(20)) THEN 1 ELSE 0 E...

Is there a difference SMO ServerConnection transaction methods versus using the SqlConnectionObject property?

I am using SMO to create databases and tables on a SQL Server. I want to do so in a transaction. Are both of these methods of doing so valid and equivalent: First method: Server server; //... server.ConnectionContext.BeginTransaction(); //... server.ConnectionContext.CommitTransaction(); Second method: Server server; // ... SqlCon...

Picking Random Names

I saw an interesting post sometime back but with no solution. Trying luck here: There is a table which contain 10 names (U1, U2, U3..and so on). I have to choose 5 names everyday, and display one as the Editor and 4 as Contributors While selecting the random names, I have to also consider that if one user is selected as Editor, he can...

CONTAINSTABLE with wildcard works different in SQL Server 2005 and SQL Server 2008?

I have two same databases one on SQL Server 2005 and one on SQL Server 2008, it have same SQL_Latin1_General_CP1_CI_AS Collation, and full text search catalogs have the same settings. These two databases contains table with same data, NTEXT string: "...kræve en forklaring fra miljøminister Connie Hedegaard.." My problem is: CONTAINST...

how can a databse be created on sql server 2005 using c# vs08.

to create new a new databse file start sql server management studio express on db server and create it! i would like to create a database using c# in my web application visual studio 08 is it possible? as connection string has to have a name of database to connect, but i want to create one. ...

how to query the database without accessing the tables, correct the database but not the tables

used is c# sql vs 08 sql server 2005 express whenever and where ever an sql select statement is used, its always like select * from tablename or count statement is alsi like select count something from table name for selecting or doing anything on the tables, i would like to know which tables exits in my the database i am connec...

In SQL Server, how can I test the instance I'm currently connecting is default or not?

Hi guys, In SQL Server, how can I test the instance I'm currently connecting is default or not? I mean how can I using TSQL to get this information? Thanks. ...

How can i rename my column in sql table?

how can i rename column name via alter table in Ms sql 2005 forexample: alter table tablename rename "old col name" to "new col name" ...