473,386 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

need sql to condense request and add an and/or statement

in sql each pt_type can several different lines of information, each with a different pt_reference

so word 1 and 2 might be in the same row, but word 3 might be in a different row but have the same "d_id", but if all 3 values are matched, then I want to know the unique "d_id" for each unique matching result.

in the case below, 1941 and 2991 would be displayed

is it also to have an and/or type of excel statement? I noted in the query below where I need it.


THANK YOU


id d_id pt_type pt_ref pt_value
3278764 69765 11 999 J0SB
4658482 67811 11 8 screen
2892238 47499 0 1 CRL Custom Finish P7 Series 36" End Post Swivel Fitting Railing Kit
4069940 1941 11 4 this
2793773 8756 0 1 CRL Black Die Cast Sliding Screen Door Pull With 2-3/8" Screw Holes
2892239 47500 0 1 CRL Custom Finish P7 Series 36" Corner Post Swivel Fitting Railing Kit
4161303 14657 11 1 TRANSACTION
4176252 29539 11 2 railing
4184049 1941 11 9 that
4188079 33720 11 3 railing
2762021 1941 0 1 theother
2762022 34055 1 1 C1DP42BRZ_34055.gif
3254121 3236 5 1 Face Diameter::2 in (50.8 mm)
5001800 31146 16 1 CRL Abrazadera de manguito a presión para cristal, 90 grados, en cobre cepillado antiguo
2762024 2991 1 2 this is a test
4191045 2991 11 2 and that is two
2794393 2991 1 1 other one



Expand|Select|Wrap|Line Numbers
  1. declare @word1 varchar(501)
  2. declare @word2 varchar(501)
  3. declare @word3 varchar(501)
  4. set @word1 = '%this%'
  5. set @word2 = '%that%'
  6. set @word3 = '%theother%'
  7. select
  8. productheader.ph_id,
  9. productheader.ph_product
  10. from productheader
  11. inner join producttext
  12. on productheader.ph_id = producttext.pt_productid
  13. where (producttext.pt_type = '11' and producttext.pt_type = '0') 
  14. --want and and/or type statement on the line right above
  15. and 
  16. (producttext.pt_value like 
  17. @word1
  18. and producttext.pt_value like 
  19. @word2
  20. and producttext.pt_value like 
  21. @word3
  22. )
Sep 3 '10
88 3250
ck9663
2,878 Expert 2GB
Will this work:

sample data population..
Expand|Select|Wrap|Line Numbers
  1.  
  2. declare @YourTable as table
  3. (
  4.    pt_ID int,
  5.    pt_productID int,
  6.    pt_Type smallint,
  7.    pt_Reference smallint,
  8.    pt_Value varchar(500)      
  9. )
  10.  
  11. declare @word1 varchar (500), @word2 varchar (500), @word3 varchar (500)
  12.  
  13. insert into @YourTable
  14. select 2960882, 12357, 0, 1, 'CLR 7/16" Steel Sliding Window'
  15. union all
  16. select 4741884, 12357, 11, 1, 'window'
  17. union all
  18. select 3278764, 69765, 11, 999, 'J0SB'
  19. union all
  20. select 4658482, 67811, 11, 8, 'screen'
  21. union all
  22. select 2892238, 47499, 0, 1, 'CRL Custom Finish P7 Series 36" End Post Swivel Fitting Railing Kit'
  23. union all
  24. select 4069940, 1941, 11, 4, 'this'
  25. union all
  26. select 2793773, 8756, 0, 1, 'CRL Black Die Cast Sliding Screen Door Pull With 2-3 8" Screw Holes'
  27. union all
  28. select 2892239, 47500, 0, 1, 'CRL Custom Finish P7 Series 36" Corner Post Swivel Fitting Railing Kit'
  29. union all
  30. select 4161303, 14657, 11, 1, 'TRANSACTION'
  31. union all
  32. select 4176252, 29539, 11, 2, 'railing'
  33. union all
  34. select 4184049, 1941, 11, 9, 'that'
  35. union all
  36. select 4188079, 33720, 11, 3, 'railing'
  37. union all
  38. select 2762021, 1941, 0, 1, 'theother'
  39. union all
  40. select 2762022, 34055, 1, 1, 'C1DP42BRZ_34055.gif'
  41. union all
  42. select 3254121, 3236, 5, 1, 'Face Diameter::2 in (50.8 mm)'
  43. union all
  44. select 5001800, 31146, 16, 1, 'CRL Abrazadera de manguito a presión para cristal, 90 grados, en cobre cepillado antiguo'
  45. union all
  46. select 2762024, 2991, 1, 2, 'this is a test'
  47. union all
  48. select 4191045, 2991, 11, 2, 'and that is two'
  49. union all
  50. select 2794393, 2991, 1, 1, 'other one'
  51. union all
  52. select 2960910, 12359, 0, 1, 'CLR 1/2" Steel Sliding Window'
  53.  
  54.  
T-SQL

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. set @word1 = '%window%';
  4. set @word2 = '';
  5. set @word3 = '';
  6.  
  7. ;with pt0
  8. as(
  9. select pt_productid 
  10. from @YourTable
  11. where pt_value like '%' + @word1 + '%' + @word2 + '%' + @word3 and pt_type = 0
  12. group by pt_productid 
  13. )
  14. ,
  15. pt1
  16. as (
  17. select pt_productid
  18. from @YourTable
  19. where pt_value like '%' + @word1 + '%' + @word2 + '%' + @word3 and pt_type <> 0
  20. group by pt_productid 
  21. )
  22. select pt0.pt_productid from pt0
  23. union all
  24. select pt1.pt_productid from pt1
  25. where pt1.pt_productid not in (select pt0.pt_productid from pt0)
  26.  
  27.  
Good Luck!!!

~~ CK
Sep 14 '10 #51
Correct. If one, two or three words are searched, then if those 3 words are anywhere in the combined records of any pt_productid either all somewhere on one line, or in any combination of pt_productid lines, then that record is returned.

Then it continues to search for the same condition.

If searching for say two words

If one pt_productid has one word that is a pt_type of 0 and one word is a pt_type of 11. and there is another pt_productid that has both words as pt_type 11 that result would be after the first

Likewise if a pt_productid had both words as a pt_type of 0, that record would be above

pt_type = 0 higher ranking than pt_type = 11

(if matching values, then order by pt_productid)

Thank you
Sep 14 '10 #52
Unfort it says
Server: Msg 170, Level 15, State 1, Line 5
Line 5: Incorrect syntax near '*'.

If I run with or without declare message, it error's here
set*@word1*=*'%window%';

(looks like there is an error i dont see)

see attached

Sep 14 '10 #53
ck9663
2,878 Expert 2GB
Sorry, I forgot CTE is not working on your side...

Try this

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. select pt0.pt_productid 
  4. from 
  5. (
  6.    select pt_productid 
  7.    from @YourTable
  8.    where pt_value like '%' + @word1 + '%' + @word2 + '%' + @word3 and pt_type = 0
  9.    group by pt_productid 
  10. ) pt0
  11. union all
  12. select pt1.pt_productid 
  13. from 
  14. (
  15.    select pt_productid
  16.    from @YourTable
  17.    where pt_value like '%' + @word1 + '%' + @word2 + '%' + @word3 and pt_type <> 0
  18.    group by pt_productid 
  19. )pt1
  20. where pt1.pt_productid not in 
  21.    (select pt3.pt_productid 
  22.     from 
  23.     (
  24.       select pt_productid 
  25.       from @YourTable
  26.       where pt_value like '%' + @word1 + '%' + @word2 + '%' + @word3 and pt_type = 0
  27.       group by pt_productid     
  28.     ) pt3   
  29.    )
  30.  
  31.  
Good Luck!!!


~~ CK
Sep 14 '10 #54
I am sure I am killing you on this!

Same error Line 1: Incorrect syntax near '*'.

set*@word1*=*'%window%';

~~running SQL server 2005 if that matters

Sep 14 '10 #55
ck9663
2,878 Expert 2GB
I don't have any asterisk on my code. Why is it showing in yours?

~~ CK
Sep 14 '10 #56
It is a copy and paste thing, there is not *** in the actual SQL, look at the image on my last post.

See if this snippet works from notepad


declare @word3 varchar(501)
set @word1 = '%window%';
set @word2 = '';
set @word3 = '';
select pt0.pt_productid
from
Sep 14 '10 #57
NeoPa
32,556 Expert Mod 16PB
From your posted pic it seems clear that one of your quote characters is not being treated as such. Maybe it's a slanted quote from a word processor or something. The red in the code says that it is treating the rest of your whole procedure as a string literal that starts at the point the string should be terminated (at the end of the fourth line).
Sep 14 '10 #58
The stars were actually tabs or spaces from the copy and paste from the browser, to SQL, then back.

When I removed all spacing on SQL, the query worked!!!
:-) exactly as requested.

What is the dif between pt0 and pt3
Sep 14 '10 #59
ck9663
2,878 Expert 2GB
Nothing. The point is to eliminate those records that's already in pt0. Your requirement says you only need the pt_id once, not repeating. It was named pt3 to identify it from pt0.

Happy Coding!!!

~~ CK
Sep 14 '10 #60
Actually I spoke too soon.

Just tried all different conditions, and if both (all) words are pt_type = 11 it returns no results.

(and when the same word is in a pt_type = 0 and pt_type = 11 it moves it to the bottom half of the list)

Side note: since a tweak is needed, can there be a pt_type = 31 added which is higher priority in the listing than 0

so first 31 then 0 then 11


thanks again
Sep 14 '10 #61
ck9663
2,878 Expert 2GB
So, has this been answered? There's already a chosen answer and yet I saw a question as last post...

So-Cal, is this done?

~~ CK
Sep 15 '10 #62
it was but after all testing for all conditions, there were some glitches, so not totally working.
Sep 15 '10 #63
ck9663
2,878 Expert 2GB
Based on my sample data, could you give me a word that's giving you the problem...

and when the same word is in a pt_type = 0 and pt_type = 11 it moves it to the bottom half of the list

~~ CK
Sep 15 '10 #64
using the query from post 54

and the data from example.pdf from POST 43

if i search for

set @word1 = 'steel';
set @word2 = 'sliding';
set @word3 = 'hardware';

nothing is returned
Sep 15 '10 #65
ck9663
2,878 Expert 2GB
And it should've returned what?


~~ CK
Sep 15 '10 #66
12357
12359

(and 12358 although you cant see the word SLIDING on that record on the PDF)
Sep 15 '10 #67
NeoPa
32,556 Expert Mod 16PB
I admit I don't get the bit about the weighting of PT_Types. Surely the values of PT_Type could vary across a group (unless they can't and you haven't told us this, but that would be a big thing to miss out).

Anyway, if it helps (and you may decide that CK's solutions are preferable. I know I've let this run for a while thinking it was fully covered already) then good. Otherwise no probs. I expect CK has you covered anyway.

For what it's worth though, this should handle the scenarios where more than one of your search items are found within the same record. That was never designed for before, as it wasn't made clear it was required until later. Anyway, see if this is any help :

Expand|Select|Wrap|Line Numbers
  1. declare @word1 varchar(501)
  2. declare @word2 varchar(501)
  3. declare @word3 varchar(501)
  4. DECLARE @Result varchar(3)
  5.  
  6. set @word1 = '%exterior%';
  7. set @word2 = '%securing%';
  8. set @word3 = '';
  9.  
  10. SET @Result = CASE ''
  11.                   WHEN @word2 THEN 'A'
  12.                   WHEN @word3 THEN 'AB'
  13.                   ELSE 'ABC'
  14.               END;
  15.  
  16. SELECT   PT_ProductID
  17. FROM     (
  18.     SELECT DISTINCT
  19.            PT_ProductID
  20.          , CASE
  21.                WHEN PT_Value LIKE @Word1 THEN 'A'
  22.                ELSE NULL
  23.            END AS [MatchA]
  24.          , CASE
  25.                WHEN (@Word2 > '') AND (PT_Value LIKE @Word2) THEN 'B'
  26.                ELSE NULL
  27.            END AS [MatchB]
  28.          , CASE
  29.                WHEN (@Word3 > '') AND (PT_Value LIKE @Word3) THEN 'C'
  30.                ELSE NULL
  31.            END AS [MatchC]
  32.     FROM   [ProductText]
  33.     WHERE  (PT_Type In('0','11'))
  34.       AND ((PT_Value LIKE @Word1)
  35.        OR  (PT_Value LIKE @Word2)
  36.        OR  (PT_Value LIKE @Word3))
  37.     ) AS cte
  38. GROUP BY PT_ProductID
  39. HAVING  (MAX([MatchA]) + 
  40.          MAX([MatchB]) + 
  41.          MAX([MatchC]) = @Result);
Sep 16 '10 #68
Thank you for your assistance.

I ran this using a set of different words.

set @word1 = '%white%';
set @word2 = '%silicone%';
set @word3 = '%sealant%';

The image link (Attached) is one of many records that contain each of the words in one or more records, for this same pt_productid.

Unfortunately the query produced 0 results.

Sep 16 '10 #69
NeoPa
32,556 Expert Mod 16PB
That looks like a string manipulation issue. 'A' + 'B' + NULL resolves to NULL and not to 'AB'. Let me have another look and I'll come back to you.
Sep 16 '10 #70
NeoPa
32,556 Expert Mod 16PB
Please test what happens if you add the following line in before line #10
Expand|Select|Wrap|Line Numbers
  1. SET CONCAT_NULL_YIELDS_NULL OFF;
This is session level and just a test. It is not good practice to use this, but it will tell us if we're on the right track.
Sep 16 '10 #71
It returns 2 records, but not this record, while ignoring the 3rd word
Sep 16 '10 #72
NeoPa
32,556 Expert Mod 16PB
I'm not clear on exactly what you're saying here. Is the data still the data from the attachment in post #69? From that I would only expect one possible record returned, or are you saying there is much more data (that I know nothing of) but that it returns nothing for PT_ProductID=1043 (the detailed data of which we know all about)?

PS. It's a shame sending databases is not as easy as with Access (generally). I'd love to get my hands on this and see what it is that I'm not understanding clearly here.
Sep 16 '10 #73
Yes, that data is still there, in this subset there are a lot more records.

I was just saying that it did return valid data, just not complete / correct results.

It should of but didnt return record 1043 as it should of
Sep 16 '10 #74
NeoPa
32,556 Expert Mod 16PB
I'm not clear what's happening here as I tested MAX() with values that included NULLs and without and it behaved as expectedly. I'm using version 2005.

Perhaps you could run another dummy test for me and post just the records returned for 1043 :

Expand|Select|Wrap|Line Numbers
  1. declare @word1 varchar(501)
  2. declare @word2 varchar(501)
  3. declare @word3 varchar(501)
  4. DECLARE @Result varchar(3)
  5.  
  6. set @word1 = '%exterior%';
  7. set @word2 = '%securing%';
  8. set @word3 = '';
  9.  
  10. SET CONCAT_NULL_YIELDS_NULL OFF;
  11.  
  12. SET @Result = CASE ''
  13.                   WHEN @word2 THEN 'A'
  14.                   WHEN @word3 THEN 'AB'
  15.                   ELSE 'ABC'
  16.               END;
  17.  
  18. SELECT DISTINCT
  19.        PT_ProductID
  20.      , CASE
  21.            WHEN PT_Value LIKE @Word1 THEN 'A'
  22.            ELSE NULL
  23.        END AS [MatchA]
  24.      , CASE
  25.            WHEN (@Word2 > '') AND (PT_Value LIKE @Word2) THEN 'B'
  26.            ELSE NULL
  27.        END AS [MatchB]
  28.      , CASE
  29.            WHEN (@Word3 > '') AND (PT_Value LIKE @Word3) THEN 'C'
  30.            ELSE NULL
  31.        END AS [MatchC]
  32. FROM   [ProductText]
  33. WHERE  ([PT_ProductID] = 1043)
  34.   AND  (PT_Type In('0','11'))
  35.   AND ((PT_Value LIKE @Word1)
  36.    OR  (PT_Value LIKE @Word2)
  37.    OR  (PT_Value LIKE @Word3))
Sep 16 '10 #75
0 results for
exterior
securing

for
white
silicone
sealant

1043 NULL NULL C
1043 NULL B NULL
1043 A B C

I am 2005 also
Sep 16 '10 #76
NeoPa
32,556 Expert Mod 16PB
Thank you. That's very interesting. It tells me that the subquery appears to be working perfectly, and as expected. I will look more closely at how this is brought together when I get a sec and see what I discover.

PS. The 'white', 'silicone', & 'sealant' is the data I am working on for now. If we can manage to get that to work we can check other sets and include an attempt that uses fewer than three matches.
Sep 17 '10 #77
NeoPa
32,556 Expert Mod 16PB
Could you also tell me what @Result resolved to during that test. Bearing in mind the results already posted, I'm struggling to see why 1043 would not have been returned from the whole SQL set. The data is as expected. What's not as I anticipate I wonder.
Sep 17 '10 #78
?????? what @Result resolved to

Dont understand the question
Sep 17 '10 #79
NeoPa
32,556 Expert Mod 16PB
OK. Let me see if I can clarify.

In the code you were running there is a local variable set up and used, called @Result (Line #12 of post #75). It is the value of this that I'm interested in.

To get this value follow these steps :
  1. Add this line after line #16 in the SQL from post #75 :
    Expand|Select|Wrap|Line Numbers
    1. PRINT '@Result = "' + @Result + '"';
  2. When you have rerun the test click on the Messages tab in SQL Server Management Studio. You will see the result (of printing @Result) in there and it will be copyable to paste in here in your new post.
Sep 17 '10 #80
In the messages tab this is all that is shown

@Result = "ABC"

(3 row(s) affected)
Sep 17 '10 #81
NeoPa
32,556 Expert Mod 16PB
That's quite as expected. What I still don't understand is why the individual pieces are all working perfectly, yet the stuff that puts them togather can't seem to work properly :S

Give me some time to put together another test that may take us forward again. It's not straightforward, as I don't see where it's failing.
Sep 17 '10 #82
NeoPa
32,556 Expert Mod 16PB
Try this now, and post what you see. It now displays @Result in the grid so switching to Messages is no longer important :) I also changed it to handle NULL values before the concatenation rather than relying on SET CONCAT_NULL_YIELDS_NULL OFF.

Expand|Select|Wrap|Line Numbers
  1. declare @word1 varchar(501)
  2. declare @word2 varchar(501)
  3. declare @word3 varchar(501)
  4. DECLARE @Result varchar(3)
  5.  
  6. set @word1 = '%white%';
  7. set @word2 = '%silicone%';
  8. set @word3 = '%sealant%';
  9.  
  10. SET @Result = CASE ''
  11.                   WHEN @word2 THEN 'A'
  12.                   WHEN @word3 THEN 'AB'
  13.                   ELSE 'ABC'
  14.               END;
  15.  
  16. SELECT @Result AS [@Result];
  17.  
  18. SELECT DISTINCT
  19.        PT_ProductID
  20.      , CASE
  21.            WHEN PT_Value LIKE @Word1 THEN 'A'
  22.            ELSE NULL
  23.        END AS [MatchA]
  24.      , CASE
  25.            WHEN (@Word2 > '') AND (PT_Value LIKE @Word2) THEN 'B'
  26.            ELSE NULL
  27.        END AS [MatchB]
  28.      , CASE
  29.            WHEN (@Word3 > '') AND (PT_Value LIKE @Word3) THEN 'C'
  30.            ELSE NULL
  31.        END AS [MatchC]
  32. FROM   [ProductText]
  33. WHERE  (PT_Type In('0','11'))
  34.   AND ((PT_Value LIKE @Word1)
  35.    OR  (PT_Value LIKE @Word2)
  36.    OR  (PT_Value LIKE @Word3));
  37.  
  38. SELECT   PT_ProductID
  39.        , ISNULL(MAX([MatchA]), '') + 
  40.          ISNULL(MAX([MatchB]), '') + 
  41.          ISNULL(MAX([MatchC]), '') AS [Comparator]
  42. FROM     (
  43.     SELECT DISTINCT
  44.            PT_ProductID
  45.          , CASE
  46.                WHEN PT_Value LIKE @Word1 THEN 'A'
  47.                ELSE NULL
  48.            END AS [MatchA]
  49.          , CASE
  50.                WHEN (@Word2 > '') AND (PT_Value LIKE @Word2) THEN 'B'
  51.                ELSE NULL
  52.            END AS [MatchB]
  53.          , CASE
  54.                WHEN (@Word3 > '') AND (PT_Value LIKE @Word3) THEN 'C'
  55.                ELSE NULL
  56.            END AS [MatchC]
  57.     FROM   [ProductText]
  58.     WHERE  (PT_Type In('0','11'))
  59.       AND ((PT_Value LIKE @Word1)
  60.        OR  (PT_Value LIKE @Word2)
  61.        OR  (PT_Value LIKE @Word3))
  62.     ) AS cte
  63. GROUP BY PT_ProductID
  64. HAVING  (ISNULL(MAX([MatchA]), '') + 
  65.          ISNULL(MAX([MatchB]), '') + 
  66.          ISNULL(MAX([MatchC]), '') = @Result);
  67. GO
This code is a little longer, but much of it is for extra information. It's not anything we expect to end up using :)
Sep 17 '10 #83
@result
ABC

1043 A B C

1043 ABC
Sep 17 '10 #84
NeoPa
32,556 Expert Mod 16PB
If the last line is titled [T_ProductID] and [Comparator] then that indicates it's actually working properly, so try the following with your main data and say if it works :
Expand|Select|Wrap|Line Numbers
  1. declare @word1 varchar(501)
  2. declare @word2 varchar(501)
  3. declare @word3 varchar(501)
  4. DECLARE @Result varchar(3)
  5.  
  6. set @word1 = '%white%';
  7. set @word2 = '%silicone%';
  8. set @word3 = '%sealant%';
  9.  
  10. SET @Result = CASE ''
  11.                   WHEN @word2 THEN 'A'
  12.                   WHEN @word3 THEN 'AB'
  13.                   ELSE 'ABC'
  14.               END;
  15.  
  16. SELECT   PT_ProductID
  17. FROM     (
  18.     SELECT DISTINCT
  19.            PT_ProductID
  20.          , CASE
  21.                WHEN PT_Value LIKE @Word1 THEN 'A'
  22.                ELSE NULL
  23.            END AS [MatchA]
  24.          , CASE
  25.                WHEN (@Word2 > '') AND (PT_Value LIKE @Word2) THEN 'B'
  26.                ELSE NULL
  27.            END AS [MatchB]
  28.          , CASE
  29.                WHEN (@Word3 > '') AND (PT_Value LIKE @Word3) THEN 'C'
  30.                ELSE NULL
  31.            END AS [MatchC]
  32.     FROM   [ProductText]
  33.     WHERE  (PT_Type In('0','11'))
  34.       AND ((PT_Value LIKE @Word1)
  35.        OR  (PT_Value LIKE @Word2)
  36.        OR  (PT_Value LIKE @Word3))
  37.     ) AS cte
  38. GROUP BY PT_ProductID
  39. HAVING  (ISNULL(MAX([MatchA]), '') + 
  40.          ISNULL(MAX([MatchB]), '') + 
  41.          ISNULL(MAX([MatchC]), '') = @Result);
  42. GO
Sep 17 '10 #85
The results are very good and appear correct, no it is just the ordering issue.

I see that I can change one of your lines to
(PT_Type In('0','11','31'))

What would I add so that it sort

if something is in 31
1st
if something is in 0
2nd
if something is in 11
3rd

and in each of these 3 groups by pt_productid

Thank you
Sep 17 '10 #86
NeoPa
32,556 Expert Mod 16PB
As far as I understand it you can't. I haven't dealt with this earlier as it is very confusing trying to deal with multiple issues at the same time, and you didn't have the basic question sorted out until quite recently, let alone a viable answer. Now that it appears that part is out of the way we can put it aside and focus on why this part of the question doesn't make sense (ceratinly as you've described it so far).

If I have any details wrong then please tell me, but I'm working from what I understand you to have explained so far. I believe I have understood everything you've posted, so this should be accurate. Let's see.

[PT_Type] is a field that is associated with your records, but it is not a field that is aggregated upon. Unlike [PT_ProductID] (See the GROUP BY clause). As such, when the data is aggregated, [PT_Type] can only be accessed by using it within an aggregate function (Sum(); Max(); Avg(); Last(); etc). How could it possibly make sense otherwise? [PT_ProductID], because it is the same value, by definition, for each of the records within the aggregated group, is available to use. The value is predictable. [PT_Type] on the other hand, may well have various values for the individual records within the aggregated group, but what does the value of [PT_Type] mean when directed at the group itself (which is the resultant data you are now working with)? It can have no value of course. It is undefined. There is a Max([PT_Type]). There is a value usable for all of the aggregate functions, but direct access to a value for [PT_Type] itself makes no sense. Hence, I am unable to help you to sort by this value, that doesn't exist in logical reality.

Expand|Select|Wrap|Line Numbers
  1. PT_ProductID  PT_Type  PT_Value
  2. 12665            0     White
  3. 12665            0     Silicone
  4. 12665           11     Sealant
  5. 12734            0     White
  6. 12734           31     Silicone
  7. 12734           11     Sealant
Study the data above and you will see why sorting as you've suggested can make no logical sense.
Sep 20 '10 #87
This might further confuse you.

Please let me clarify. Each pt_id in this table is a unique record.

Each record may not have a unique pt_productid in this table, and may have multiple entries.

The input would look at all pt_type's of 0, 11, and 31. Each of these records can have more than one word, so matching any of the words in each records is ok, thus the % %.

Each pt_productid can have multiple pt_types of the same number, and can have multiples of all 3 pt_types per pt_productid, the further definition that makes each one unique is pt_reference (even though this is not refered to in the query)

0 is top level
31 is middle level
11 is bottom level

For instance, if there are 3 matching pt_product's, then this is how the sorting would work best.

If there were two words searched for, and both words were matched for each of the 3 records, what ever word was matched in the highest level, would be sorted according to the above.


Thank you
Sep 21 '10 #88
ck9663
2,878 Expert 2GB
Sorry guys..it's getting more confusing... :)

I have not used your pdf as sample data...Too many to type. Can you attached a delimited text file as sample data, give some words that you are searching and the records that you want returned?

As I understand it, you want to combine all strings of the same pt_product_id, if all words exists somewhere on that string, that pt_product_id record is returned.

In this case, you will be combining the string regardless of pt_type. However, if one of the pt_type of those records with the same pt_product_id is equal to 31, that should be return first even if the text you are looking for is found in record with pt_type = '11'...

Did I even make sense ? :)


~~ CK
Sep 21 '10 #89

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: David Hitillambeau | last post by:
Hi guys, As I am new to Python, i was wondering how to declare and use global variables. Suppose i have the following structure in the same module (same file): def foo: <instructions>...
3
by: JT | last post by:
is there a way to clear out the request.form collection, or the entire request object, for that matter?? im using server.transfer and this can be troublesome in cases where you need the...
18
by: deanbrown3d | last post by:
I mean, is this correct? try { Screen->Cursor = crHourglass; Do something bad return false; else return true; }
7
by: bizt | last post by:
Hi, I have an Intranet with the organisation I work with. In this organisation there are two departments - community department and press office. Both the community department and press office...
2
by: A Traveler | last post by:
Hello, Given that a particular iis server has its session timeout set to the default of 20mins, what will renew the request in order to prevent it timing out? Is it only code-type things, such...
5
by: Digital Fart | last post by:
I have 3 strings containing "10" , "20", ">=" would it be possible via reflection to generate a dynamic if statement that return true or false and testing it like this if ( 10 >= 20 ) so a...
1
by: jburris | last post by:
I am completely new to VBA. I am trying to update a yes/no box in a subform based on a value that I call from the main form into the subform. Below is the if /then statement i am using: If...
20
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
I always have trouble writing a SQL statement when it comes to the handling of the quotes. Can someone please help me with this line of ocde? I know I need to have "Armed Away" in quotes too (I...
4
by: spargos | last post by:
I'm having significant trouble getting the scriptalicious or dojo toolkits to work for me. For instance I'm trying to implement a simple blinddown in my page. If I were to do this: <div...
6
by: daryl | last post by:
Can someone please help?! I need to add a calling statement to the end of the script that calls the checkGrade() function and passes to it the value from the grade form variable. Nothing I tried...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.