code_junkie

Is there a way to make Crystal Reports include a constant in a join condition, without using a SQL command object?

Nov 11th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. SELECT a.id, a.other, b.baz
  2. FROM a
  3. LEFT OUTER JOIN b
  4. ON a.id = b.id
  5. AND b.bar = 'foo'
  6.  
  7. SELECT a.id, a.other, b.baz
  8. FROM a
  9. LEFT OUTER JOIN b
  10. ON a.id = b.id
  11. WHERE (b.bar IS NULL OR b.bar = 'foo')
  12.  
  13. SELECT a.id, a.other, b.baz
  14. FROM a
  15. LEFT OUTER JOIN b
  16. ON a.id = b.id
  17. WHERE (b.bar IS NULL OR b.bar = 'foo')
  18.  
  19. CREATE TABLE a (id INTEGER, other VARCHAR(32));
  20. CREATE TABLE b (id INTEGER, bar VARCHAR(32), baz VARCHAR(32));
  21. insert into A (id, other) values ('1', 'Has foo');
  22. insert into A (id, other) values ('2', 'Has none');
  23. insert into A (id, other) values ('3', 'Has foobar');
  24. insert into B (id, bar, baz) values ('1', 'foo', 'Include');
  25. insert into B (id, bar, baz) values ('1', 'foobar', 'Exclude');
  26. insert into B (id, bar, baz) values ('1', 'another', 'Exclude');
  27. insert into B (id, bar, baz) values ('1', 'More', 'Exclude');
  28. insert into B (id, bar, baz) values ('3', 'foobar', 'Exclude');
  29.  
  30. CREATE TABLE a (id INTEGER, other VARCHAR(32));
  31. CREATE TABLE b (id INTEGER, bar VARCHAR(32), baz VARCHAR(32));
  32. insert into A (id, other) values ('1', 'Has foo');
  33. insert into A (id, other) values ('2', 'Has none');
  34. insert into A (id, other) values ('3', 'Has foobar');
  35. insert into B (id, bar, baz) values ('1', 'foo', 'Include');
  36. insert into B (id, bar, baz) values ('1', 'foobar', 'Exclude');
  37. insert into B (id, bar, baz) values ('1', 'another', 'Exclude');
  38. insert into B (id, bar, baz) values ('1', 'More', 'Exclude');
  39. insert into B (id, bar, baz) values ('3', 'foobar', 'Exclude');
  40.  
  41. SELECT a.id, x.baz
  42. FROM a
  43. LEFT OUTER JOIN
  44. (SELECT id, baz FROM b WHERE bar = 'foo') As x ON a.id = x.id
  45.  
  46. (Isnull({b.bar}) OR {b.bar} = "foo")
Add Comment
Please, Sign In to add comment