sql-server-2008

Import contacts from SQL Server to Outlook

I'm having some trouble getting personal contacts of some users I have in a database in SQL Server 2008. I need to import into Outlook, so I can send an email to each one. What is the best way for me to be able to connect to the database and get the contacts? Thanks. ...

How do you create a cumulative, "derived" column of ancestry using SQL Server 2008 hierarchyid

Imagine your typical manager / employee hierarchy, where you have an employee with a boss, who in turn has a boss, who in turn has a boss. How would you write a query that would have a column with, say, all the boss's names as a varchar. Given this data (leaving out the hierarchyid column but the id column here essentially describes th...

How to grant users read-only access to all databases

I want a group of users to have read-only access to all tables and views on all databases on SQL Server (I'm using SS2008). I'd like those users to have read-only access to all future tables and view. How would you set that up? ...

SQL Server login failure in middle of application run

I have an application that suddenly started throwing the following exception: System.Data.SqlClient.SqlException: Login failed for user 'username'. The username and password are correct and the app does some queries/inserts using the same login before throwing the exception. What are some other reasons a login can start failing? ...

Splitting a delimeted string with 2 values .SQL Server 2008 . Can you help?

I am passing a delimited string to a stored procedure that is composed by empId|ProductId + a comma as delimiter with the purpose of filling a link table. using SQL Server 2008 EmployeeOrderLink Table to be filled EmpId OrderId ProductId Example of a possible key MyKeyIds="EmpId|ProductId, EG 2232|33,45...

Encrypting Whole Database

I need to encrypt whole databse, not any specific column in the database. This should be done in SQL 2008 or in SQL 2008 Express edition If any one can, do favour for this ...

SQL Server Schema to Schema Migration

I would like to know which one is the best approach for migrating existing DB data to another new DB with entirely different structure. I want to copy the data from my old DB and need to insert the data in new DB. For me the table names and column names of new DB is entirely different. I am using SQL Server 2008. ...

How to encrypt data in sql server and decrypt it in .net apps

I want to encrypt some passwords in sql server and have a c# app decrypt them. Obviously I can create an SP to decrypt the required password for me and pass this to the c# app, but this means sending the plaintext password over network. So I want to be able to encrypt my password in sql server (using passphrase, certificate etc), w...

Merge data from one table to anoter with FK

Dear SO :) I have to merge data from one table to another. Both of these tables have the same structure, something like this: Id (PK*) | Name | ParetnId (FK to PK*, it's a tree) What I'm trying to use: Plain insert/update - too long SQL, FK/PK issues (when I copy row with ParentId to not existing row) merge operator - much shorter...

SQL Server 2008 execution plan question

Hello, I have a question addressed to sql guru. There are two tables with almost identical structure. Based on parameter passed into the stored procedure I need to collect data from one or another table. How to do that in a best way? Please do not suggest to combine those tables into single one - that is not appropriate. I did it ...

Howto access WMI in SQL CLR Projects

I have a project i've been working on that requires me to retrieve the CPU ID of the computer to create a software licence and check it against the current licens registered. So, said and done i made 2 programs to make this happen. Then i need to implement this solution into my CLR project. I notice that i can't add System.Management ...

Getting the most recent records with 2 or more related entries with SQL

Hello, I inherited an interesting table structure. This table structure looks like the following: GroupTable ID Name Description GroupItem ID GroupID Name CreatedBy CreationDate I need to get the three most recent GroupItem elements created by a specific user. The twist comes in with a requirement associated with the GroupID. T...

SQL Server Conversion Exception: Error converting data type varchar to numeric

I am working on a project where the goal is to convert an existing application to SQL Server. However, I am running into issues with ID generation - specifically, the conversion of data types. The hibernate annotations for my ID column are as follows: @Id @GeneratedValue(generator="ID_GEN", strategy=GenerationType.TABLE) @TableGenerato...

Explicit syntax for select xxx from table1,table2

I have a select statement select someFields from table1,table2 which is a cartesian join, right? What's the explicit syntax for such a join. Searching the web for , isn't yielding much luck. ...

t-sql COUNT on user defined function returned value

I have a CTE as below (logic removed) ;with cte_a as ( select ID, Count(AnotherID) as Counter from Table_A group by ID ) and a user defined function that takes an Id as input and returns a table. udf_GetRelatedItemIds(@Id) I wanted to just count the number of related item ids returned from the user defined function for ...

modify table with column with null values

what if I wanted to update the records in the table by altering values in one of the columns? I have records in the table that have one column empty(null values). I want to change these values and insert values from another table into those records. Basically I have a table with one column empty. I do not want to append to the end of t...

Code Alignment In SQL Server 2008?

I am using SQL Server Management Studio.I want to know the shortcuts for easily aligning the T-SQL Queries similiar to ctrl+k+d in visual studio. ...

Is there an equivalent to 'mysqladmin processlist' for SQL Server?

I've been trying to formulate a query to help myself identify resource-heavy queries/database/users using SQL Server and haven't gotten it down quite yet. I want to build a query that will do what 'mysqladmin processlist' would do for MySQL. I've referred to this related question but haven't gotten what I really need from it. I'm usin...

For each row in SQL Server

Hello I got a table with one column eg: col1 and 5 records. Eg: tablename: Table1 Col1 ------- aaaa bbbb cccc dddd eeee I want to build a string based on col1 values as something below: set @stringVariable = ''aaaa', 'bbbb', 'cccc', 'dddd', 'eeee'' How can this be done. ...

SQL Server Provider?

How to solve this Error Msg 7308, Level 16, State 1, Line 1 OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode. ...