Groups | Blog | Home
all groups > sql server programming > december 2004 >

sql server programming : Partitioned view on tables with text field


Buddy Ackerman
12/23/2004 10:22:30 PM
Is it possible to create a partitioned view on a table that has a text field in it (obviously not as a partitioning
field)? I tried but I get the following error:
"The text, ntext, or image data type cannot be selected as DISTINCT."

Anith Sen
12/23/2004 10:52:54 PM
[quoted text, click to view]

The error message is generic; the documentation ( though at an unusual
location ) states: If you have a view that includes a text field, and you
reference the text field in a SELECT clause, then you are not allowed to use
SELECT DISTINCT.
( http://msdn.microsoft.com/library/en-us/repospr/rpoptimizing_219v.asp )

--
Anith

Buddy Ackerman
12/23/2004 10:59:50 PM
I am not using DISTINCT. I was assuming that it was just a requirement of creating a partitioned view and that's why I
am getting the error. Here is the view definition:

create view dbo.vSearch_Record
AS
SELECT Search_ID, Time_Stamp, Search_On, Shopper_ID, Search_Type_ID, Min_Price, Max_Price, SKU_String,
Keyword_Input_String, Search_Schematic, Term_List_Ordered, Elapsed_Time, Hit_Count, Shopper_Client_IP, Recent,
Full_Search_Query, Generated_Clause
FROM dbo.Search_Record_current

UNION

SELECT Search_ID, Time_Stamp, Search_On, Shopper_ID, Search_Type_ID, Min_Price, Max_Price, SKU_String,
Keyword_Input_String, Search_Schematic, Term_List_Ordered, Elapsed_Time, Hit_Count, Shopper_Client_IP, Recent,
Full_Search_Query, Generated_Clause
FROM dbo.Search_Record_history


The Search_ID field in the tables are PKs and they are the partitioning field as well.



--Buddy




[quoted text, click to view]
Buddy Ackerman
12/23/2004 11:00:02 PM
I am not using DISTINCT. I was assuming that it was just a requirement of creating a partitioned view and that's why I
am getting the error. Here is the view definition:

create view dbo.vSearch_Record
AS
SELECT Search_ID, Time_Stamp, Search_On, Shopper_ID, Search_Type_ID, Min_Price, Max_Price, SKU_String,
Keyword_Input_String, Search_Schematic, Term_List_Ordered, Elapsed_Time, Hit_Count, Shopper_Client_IP, Recent,
Full_Search_Query, Generated_Clause
FROM dbo.Search_Record_current

UNION

SELECT Search_ID, Time_Stamp, Search_On, Shopper_ID, Search_Type_ID, Min_Price, Max_Price, SKU_String,
Keyword_Input_String, Search_Schematic, Term_List_Ordered, Elapsed_Time, Hit_Count, Shopper_Client_IP, Recent,
Full_Search_Query, Generated_Clause
FROM dbo.Search_Record_history


The Search_ID field in the tables are PKs and they are the partitioning field as well.



--Buddy

[quoted text, click to view]
Buddy Ackerman
12/23/2004 11:21:14 PM
DUH, of course you're supposed to use UNION ALL when creating a partitioned view. Thanks for the catch.


[quoted text, click to view]
Adam Machanic
12/23/2004 11:52:13 PM
The issue is not creating a partitioned view, it's using DISTINCT on a text
column (just as the error says).

Why do you need to select DISTINCT?


--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--


[quoted text, click to view]
fields.

Adam Machanic
12/24/2004 12:03:55 AM
Actually, view or no view, SELECT DISTINCT is not allowed on TEXT columns:


create table #a(blah text)

select distinct blah
from #a

-- Server: Msg 8163, Level 16, State 3, Line 3
-- The text, ntext, or image data type cannot be selected as DISTINCT.

--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--


[quoted text, click to view]

Adam Machanic
12/24/2004 12:05:35 AM
Try using UNION ALL instead of UNION. I believe that partitioned views
require that anyway. UNION does a DISTINCT behind the scenes.

--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--


[quoted text, click to view]

Adam Machanic
12/24/2004 12:10:08 AM
[quoted text, click to view]


Here's verification that the same error message is produced:

create table #a(blah text)

select blah
from #a
union
select blah
from #a


.... Changing that to UNION ALL fixes the issue.

--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--

Anith Sen
12/24/2004 9:36:54 AM
True, I was simply quoting BOL since the OP stated he couldn't find it.

--
Anith

AddThis Social Bookmark Button