|
|
Up |
|
|
  |
Author: parthparth
Date: Jan 7, 2007 17:43
Hi
I want to achieve the following transformation of data using a stored
procedure.
Source
col1 col2(varchar)
-------------------------
1 1.1
1 1.2
2 2.1
2 2.2
2 2.3
=================
Desired Result
col1 col2(varchar)
--------------------------
1 1.1 | 1.2
2 2.1 | 2.2 | 2.3
=====================
Thanks in advance. :)
|
| Show full article (0.49Kb) |
|
| |
5 Comments |
|
  |
Author: dmarkledmarkle
Date: Jan 7, 2007 16:34
I suspect the reason (...AND ... IS NOT NULL) is helping you out is
that it's forcing the optimizer to choose a table scan instead if
hitting up that index you made on email.
Before you go changing minutiae like ANSI_NULLS, do realize that your
tables are, (relationally speaking), nonsense. Any table without a
PRIMARY KEY or otherwise unique key is likely going to cause problems
with the optimizer, and it often happens in bizarre ways like this.
You should do the following:
1) Make the clustered index on "bk" UNIQUE. If you can't do that...
2) Add email to your clustered index as a secondary key and recreate
the clustered index as UNIQUE, or make the combination of the two
columns a PRIMARY KEY. If you can't do that...
3) Analyze your data and fix your process to not allow wholly duplicate
rows, which are nonsensical. If you can't do THAT (ugh):
4) Add an IDENTITY column to your table. So as not to drastically
increase your index sizes, you could either add this column as a
secondary key after bk and make the clustered index UNIQUE, or you
could create a nonclustered PRIMARY KEY on that identity.
|
| Show full article (2.09Kb) |
|
| |
no comments
|
|
  |
Author: GreyGrey
Date: Jan 7, 2007 13:16
OK, now I have solved the problem by an approach I found at some other post
presented by Joe Celko:
CREATE TABLE Foobar
(id INTEGER NOT NULL PRIMARY KEY,
name CHAR(10) NOT NULL);
INSERT INTO Foobar VALUES (12, 'Johnson');
INSERT INTO Foobar VALUES (57, 'Nelson');
INSERT INTO Foobar VALUES (11, 'Roberts');
INSERT INTO Foobar VALUES (68, 'Smith');
SELECT F1.id, F1.name,
(SELECT MAX (id)
FROM Foobar AS F2
WHERE F2.id < F1.id) AS prev_id,
(SELECT MIN(id)
FROM Foobar AS F3
WHERE F3.id > F1.id) AS next_id
FROM Foobar AS F1;
These subquery expressions are the LUB (least upper
bound) and the GLB (greatest lower bound).
|
| Show full article (1.11Kb) |
|
no comments
|
|
  |
Author: diegodiego
Date: Jan 6, 2007 20:29
Greetings everyone!
Is there a way to stop query analyzer from processing remaining query
statements? Let's say i have the following query in query analyzer:
query statements
if condition
begin
query statements
stop the query
end
query statements
if condition
begin
query statements
stop the query
end
is there a way to stop the query from executing the statements in the
second query when the first condition is met?
i have searched BOL and google but i couldn't find anything. I hope
anybody out there can help me.
|
| Show full article (0.89Kb) |
|
2 Comments |
|
  |
Author: John RiversJohn Rivers
Date: Jan 6, 2007 14:37
create from dbo.fromExample
as
from dbo.Customers c
join dbo.Invoices i
on c.CustomerID = i.CustomerID
now you can use it as follows:
select c.CustomerID, i.InvoiceNo
from dbo.fromExample
I find I reuse FROM clauses alot
and reusing a "base query" requires writing a very large and cumbersome
select clause
|
| |
|
3 Comments |
|
  |
Author: Bernard PeekBernard Peek
Date: Jan 6, 2007 14:10
In message 127.0.0.1>, Erland Sommarskog
writes
>> I am new to SQL Server, and migrating part of an Access application to
>> SSE. I am trying to insert a comma delimited file into SSE 2005. I am
>> able to run a BULK INSERT statement on a simple file, specifying the
>> field (,) and row (\n) terminators. I can also do the same with a
>> format file.
>>
>> Here is the problem. My csv file has 185 columns, with a mixture of
>> datatypes. Sometimes, a text field will contain the field delimiter as
>> part of the string. In this case (and only in this case) there will be
>> double quotes around the string to indicate that the comma is part of
>> the field, and not a delimiter.
>
>So a file could look like this:
>
> 2,34,Enter Sandman,Pat Boone
> 9,34,Zabadak,"Dave, Dee, Dozy, Mich & Tich"
> 8,981,"Rebel, Rebel",David Bowie ...
|
| Show full article (2.08Kb) |
|
no comments
|
|
  |
Author: StuStu
Date: Jan 6, 2007 14:00
Erland makes a good point. The essence of any argument about
upgrading is that eventually they will have to upgrade, either to SQL
2005 or some other version. The question is: do they want to be
proactive, and take time to plan it, or do they want to be reactive,
and have their schedule for upgrading dictated by market forces.
None of our vendors that supply SQL Server products require SQL 2005,
but I'm betting that new releases this year will begin requiring SS2005
databases. In other words, our current apps don't require 2005, but
future versions may. I'd rather start planning for that contingency
now than be forced into it by a necessary patch for a vendor software.
I'm not saying that upgrades are the only option; could always buy a
new server for applications that require SS2005.
Stu
Erland Sommarskog wrote:
>> Like it or not SQL Server 2000 is a 7 year old product RDBMS now.
>
> 6½ to be precise. :-)
>
>> "If its not broken doesn't fix it" doesn't...
|
| Show full article (1.93Kb) |
|
no comments
|
|
  |
Author: Erland SommarskogErland Sommarskog
Date: Jan 6, 2007 06:02
> Like it or not SQL Server 2000 is a 7 year old product RDBMS now.
6½ to be precise. :-)
> "If its not broken doesn’t fix it" doesn't apply to most IT platforms
> these days, b'coz of the cost of running legacy/obsolete systems. Plus
> the cost of employing IT personnel
>
> So like it or no Microsoft is going to discontinue support for SQL
> Server 2000. Therefore your client’s got ~ 1 1/2 years to upgrade to SQL
> Server 2005. (Unless with Extended Support)
To be perfectly honest, I don't think is a very good argument for
upgrading to SQL 2005. It rather makes the argument "we can be on all
this update trains, so we wait for the next one". And Microsoft has
indicated that from now, it's a two-year release cycle for SQL Server.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
|
| Show full article (1.06Kb) |
|
no comments
|
|
  |
Author: Erland SommarskogErland Sommarskog
Date: Jan 6, 2007 05:49
> I am new to SQL Server, and migrating part of an Access application to
> SSE. I am trying to insert a comma delimited file into SSE 2005. I am
> able to run a BULK INSERT statement on a simple file, specifying the
> field (,) and row (\n) terminators. I can also do the same with a
> format file.
>
> Here is the problem. My csv file has 185 columns, with a mixture of
> datatypes. Sometimes, a text field will contain the field delimiter as
> part of the string. In this case (and only in this case) there will be
> double quotes around the string to indicate that the comma is part of
> the field, and not a delimiter.
So a file could look like this:
2,34,Enter Sandman,Pat Boone
9,34,Zabadak,"Dave, Dee, Dozy, Mich & Tich"
8,981,"Rebel, Rebel",David Bowie
|
| Show full article (1.55Kb) |
|
1 Comment |
|
  |
|
|
  |
Author: TedTed
Date: Jan 5, 2007 19:34
Erland Sommarskog wrote:
>> "Can we use a distributed SELECT statement in a view?"
>
> Yes.
>
>> and "Can we create a foreign key constraint that references a column in a
>> view?"
>
> No. Foreign keys are inside the database. To keep cross-database of
> cross-server referential integrity, you will have to use triggers.
>
>
Thanks Erland.
|
| Show full article (0.69Kb) |
|
1 Comment |
|
|
|
|
|
|