sql-server

Bulk insert into SQL Server a CSV with line breaks in fields

I have a csv that looks like this: "blah","blah, blah, blah ect, ect","column 3" "foo","foo, bar, baz more stuff on another line", "another column 3" Is it possible to import this directly into SQL server? ...

SQL - How to assign a record in a variable

AIM : Convert a resultset to XML and assign the result to a variable Result Set : M000017690 324067342 324067349 324067355 324154449 Converted XML : <Products> <Product ProductId="324067342" /> <Product ProductId="324067349" /> <Product ProductId="324067355" /> <Product ProductId="324154449" /> <Product ProductId="M0000176...

SQL Server LDAP authentication

Using SQL Server 2005, how can I authenticate a username/password pair against a non-AD LDAP server using NET ? ...

Disable SQLCMD Syntax Check

We sometimes write dataport scripts that rename tables or columns and have other complex logic. We also have SQL in IF statements referencing those old columns or tables. We have a standard to use IF statements to make our SQL Scripts multi run friendly. However occasionally, even though the if statement evaluates to false, the code w...

Global Temporary table delete operation

How to check if the global Temporary table exists in SQL server, if yes then delete that global temporary table? I am trying to execute this: IF OBJECT_ID('##Table', 'U') IS NOT NULL DROP TABLE ##Table ...but it is not working. ...

SQL Order By and "Not-So-Much Group"

Hello, Lets say I have a table: -------------------------------------- | ID | DATE | GROUP | RESULT | -------------------------------------- | 1 | 01/06 | Group1 | 12345 | | 2 | 01/05 | Group2 | 54321 | | 3 | 01/04 | Group1 | 11111 | -------------------------------------- I want to order the result by t...

How to join a one-to-many relationship to ensure that only 1 row from the left comes back?

Sorry about a vague title, but here's what i am trying to do. I have the following two tables TABLE_PERSON | TABLE_PHONE | col_Name | col_Name col_phoneID col_phoneNbr -------- | -------- ----------- ------------ Clark Kent | Clark Kent 1 111-111-1111 Bruce Wayne | Clark Kent ...

Link Server Optimization Help

I have this code in a trigger. if isnull(@d_email,'') <> isnull(@i_email,'') begin update server2.database2.dbo.Table2 set email = @i_email, where user_id = (select user_id from server2.database2.dbo.Table1 where login = @login) end I would like to update a table on another db server, both are MSSQL. the query above works for m...

Linking SQL Server view into Access db: performance question

When you attach a SQL Server view as an MS Access linked table, you are asked for a unique identifier. During recent trials, I noticed that on several occasion, NOT defining the unique identifier has the effect that the linked table opens much more quickly (you don't need a stopwatch, you can really SEE it). So I am asking the experts...

Get all topics, ordered by their last post date in a forum

I'm writing a forum. I've a TOPICS table, and a POSTS table. In the POSTS table, I have a TopicId field, and a date field. I want to get all the topics, ordered by their last post date, in a single SQL query. How can I do this? EDIT: The post's date is in the POST table. I want to check what is the last post of every post, then checki...

CHECK/NOCHECK for Sql Compact Edition

I am attempting to wipe and repopulate test data on SQL CE. I am getting an error due to FK constraints existing. Typically in Sql2005 I would ALTER TABLE [tablename] CHECK/NOCHECK CONSTRAINT ALL to enable/disable all constraints. From what I could find in my searching, it seems that this might not be supported in CE. Is that true? ...

How do I Pivot on an XML column's attributes in T-SQL

I need to perform a pivot on an XML column in a table, where the XML contains multiple elements with a number of attributes. The attributes in each element is always the same, however the number of elements will vary. Let me give an example... FormEntryId | FormXML | DateCreated =========...

How do I list all the columns in a table?

For the various popular database systems, how do you list all the columns in a table? ...

How To Insert Unique Composite ID For Hierarchical Table (SQL Server)

Hi, I have this table structured as follows : PK ParentPK ID 1 Null A 2 1 B 3 2 C 4 1 D 5 4 E For the table above, I already have a function that can generate the following results : PK FullID 3 ABC 5 ADE This function takes rows that...

How do I view previous queries in SQL Server 2000 database

How do I view previous queries in SQL Server 2000 database ...

Client Access to SQL Server over the Internet

Does anyone have any opinions over the best ways to connect a client to SQL Server to get data. So lets say I have a C# DataGridView in a Winform not on the internal network and I need to load it with a lot of data. Currently to access the data we call a component SQLDataAdapter in the client which opens a connection to the SQL server,...

SQL Server 2008 - Table - Clarifications

I am new to SQL Server 2008 database development. Here I have a master table named ‘Student’ and a child table named ‘Address’. The common column between these tables is ‘Student ID’. My doubts are: Do we need to put ‘Address Id’ in the ‘Address’ table and make it primary key? Is it mandatory? ( I won’t be using this ‘Address Id’ i...

Need some t-sql clarification

This is a follow up to my previous question, in t-sql SELECT SCOPE_IDENTITY() returns a BIGINT, I did the following to get it to return an INT: DECLARE @X INT INSERT ... SELECT @X = SCOPE_IDENTITY() -- if i don't include the line below, it will return a BIGINT SELECT @X Why does it return a BIGINT unless I do SELECT @X at the...

T-sql problem with running sum

I am trying to write T-sql script which will find "open" records for one table Structure of data is following Id (int PK) Ts (datetime) Art_id (int) Amount (float) 1 '2009-01-01' 1 1 2 '2009-01-05' 1 -1 3 '2009-01-10' 1 ...

Pb for installing SQL Server Express Management Studio 2008

Each time I launch the install, it launches the SQL Server Express 2008 panel instead of Management Studio why ? ...