I do need distinct. What I don't understand is why it works when I don't use the cast function, but doesn't when I do. With or without casting to a string the row size is the same - not nearly 8000 characters.
Main Topics
Browse All TopicsSELECT DISTINCT CAST(d.cde_question as varchar(25)), d.txt_question_text, p.cde_question, p.txt_question_text
FROM (SELECT DISTINCT dq.cde_question, dq.txt_question_text FROM WTportalna1.dbo.t_question
ON dq.cde_question = drq.cde_question
WHERE drq.cde_selsys = 1069 and drq.num_raw_score Is Not Null and dq.num_scale Is Not Null and dq.cde_question_type <> 0) d RIGHT OUTER JOIN
(SELECT DISTINCT tpq.cde_question, tpq.txt_question_text FROM ams_master_testportal.dbo.
ON tpq.cde_question = rq.cde_question
WHERE rq.cde_selsys = 1008 and rq.num_raw_score Is Not Null and tpq.num_scale Is Not Null and tpq.cde_question_type <> 0) p ON
d.txt_question_text = p.txt_question_text OPTION (ROBUST PLAN)
The above query fails with or without OPTION (ROBUST PLAN). It only fails when I try to cast a numeric field to a string field. Any ideas?
-David
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Why don't you load the part your joining into a temp table.
SELECT DISTINCT tpq.cde_question, tpq.txt_question_text
INTO #TMP
FROM ams_master_testportal.dbo.
ON tpq.cde_question = rq.cde_question
WHERE rq.cde_selsys = 1008 and rq.num_raw_score Is Not Null and tpq.num_scale Is Not Null and tpq.cde_question_type <> 0
Then
SELECT DISTINCT CAST(d.cde_question as varchar(25)), d.txt_question_text, p.cde_question, p.txt_question_text
FROM (SELECT DISTINCT dq.cde_question, dq.txt_question_text FROM WTportalna1.dbo.t_question
ON dq.cde_question = drq.cde_question
WHERE drq.cde_selsys = 1069 and drq.num_raw_score Is Not Null and dq.num_scale Is Not Null and dq.cde_question_type <> 0) d RIGHT OUTER JOIN
#TMP p ON
d.txt_question_text = p.txt_question_text OPTION (ROBUST PLAN)
Business Accounts
Answer for Membership
by: angelIIIPosted on 2007-02-09 at 05:51:57ID: 18501132
do you really need the DISTINCT? that is the one that makes that error message appear, besides the fact that the fields that you put in the select list have that total size....