Click here to Skip to main content
15,898,134 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Do you want string or string? Pin
KP Lee14-Feb-12 15:28
KP Lee14-Feb-12 15:28 
GeneralRe: Do you want string or string? Pin
KP Lee14-Feb-12 14:30
KP Lee14-Feb-12 14:30 
GeneralRe: Do you want string or string? Pin
Brisingr Aerowing31-Mar-12 7:04
professionalBrisingr Aerowing31-Mar-12 7:04 
GeneralBad filtering Pin
Jtai6-Feb-12 8:12
Jtai6-Feb-12 8:12 
GeneralRe: Bad filtering Pin
ekolis6-Feb-12 10:35
ekolis6-Feb-12 10:35 
GeneralRe: Bad filtering Pin
Jtai6-Feb-12 15:04
Jtai6-Feb-12 15:04 
JokeRe: Bad filtering Pin
AspDotNetDev6-Feb-12 15:24
protectorAspDotNetDev6-Feb-12 15:24 
GeneralRe: Bad filtering Pin
KP Lee14-Feb-12 17:34
KP Lee14-Feb-12 17:34 
Jtai wrote:
SQL
Select field1,field2,field3
From table1
Where type="EDU"

 


When I read the code, I thought it was a pity that Active wasn't in the DB so you could restrict the number of lines based on Active. Then I thought, don't even run the logic if Active isn't true. As I continued reading, I realized the real condition. Did you drop the Active check in the code along with modifying the select?

If it's still a large # of rows being read, you might want to include your condition checks in the selection criteria. Also, hopefully, you are really running a sproc to get your data.

Here's an example of using 4 condition checks with very different selection criteria. If two condition checks overlap then the data produced would overlap. The table had 5K rows in it, the selection had 39 rows in it.
SQL
declare @tbl table (Cond int, sTotID int, stot1 int, stot2 int, stot3 int) 
insert into @tbl
values (1,-1, 20, -1, 49), (2, 203148, -1, -1, -1), (3, -1, 15, 29, -1), (4, -1, 25, 32, -1)
SELECT TOP 1000 Cond, TotID
      ,NumbRecs
      ,tot1
      ,tot2
      ,tot3
  FROM dbo.ThreeNumberSum
  JOIN @tbl on (sTotID = -1 or sTotID = TotID) AND (stot1 = -1 OR stot1 = tot1)
	AND (stot2 = -1 OR stot2 = tot2) AND (stot3 = -1 OR stot3 = tot3)

Your code could just check 1 value to match all the multiple conditions. Here is an extract of all the rows:
Cond	TotID	NumbRecs tot1	tot2	tot3
1	202749	32	20	27	49
... middle number 28-30
1	203149	208	20	31	49
1	203249	184	20	32	49
1	203349	128	20	33	49
1	203449	56	20	34	49
1	203549	8	20	35	49
1	203649	8	20	36	49
2	203148	424	20	31	48
3	152940	24	15	29	40
3	152941	40	15	29	41
3	152942	32	15	29	42
3	152943	48	15	29	43
3	152944	8	15	29	44
3	152945	8	15	29	45
4	253228	28956	25	32	28
4	253229	49698	25	32	29
... last number 30-35
4	253236	595694	25	32	36
4	253237	529858	25	32	37
... last number 38-48
4	253249	8	25	32	49

RantDAO Framework PinPopular
Chanoch Wiggers1-Feb-12 2:06
Chanoch Wiggers1-Feb-12 2:06 
GeneralRe: DAO Framework Pin
GibbleCH1-Feb-12 5:58
GibbleCH1-Feb-12 5:58 
GeneralRe: DAO Framework Pin
Chanoch Wiggers1-Feb-12 11:27
Chanoch Wiggers1-Feb-12 11:27 
GeneralRe: DAO Framework Pin
JackDingler14-Feb-12 9:12
JackDingler14-Feb-12 9:12 
GeneralRe: DAO Framework Pin
Sander Rossel1-Feb-12 11:50
professionalSander Rossel1-Feb-12 11:50 
GeneralRe: DAO Framework Pin
Baxter R Pearson1-Feb-12 21:25
Baxter R Pearson1-Feb-12 21:25 
GeneralRe: DAO Framework Pin
Chanoch Wiggers1-Feb-12 22:42
Chanoch Wiggers1-Feb-12 22:42 
GeneralRe: DAO Framework Pin
Baxter R Pearson2-Feb-12 1:14
Baxter R Pearson2-Feb-12 1:14 
GeneralRe: DAO Framework Pin
Kirk Wood7-Feb-12 2:10
Kirk Wood7-Feb-12 2:10 
GeneralRe: DAO Framework Pin
ekolis3-Feb-12 14:59
ekolis3-Feb-12 14:59 
GeneralRe: DAO Framework Pin
User 48220337-Feb-12 0:57
User 48220337-Feb-12 0:57 
GeneralRe: DAO Framework Pin
TylerMc0077-Feb-12 8:22
TylerMc0077-Feb-12 8:22 
GeneralRe: DAO Framework Pin
Rob Grainger12-Feb-12 14:21
Rob Grainger12-Feb-12 14:21 
GeneralRe: DAO Framework Pin
cpkilekofp7-Feb-12 8:36
cpkilekofp7-Feb-12 8:36 
GeneralRe: DAO Framework Pin
ClockMeister7-Feb-12 13:11
professionalClockMeister7-Feb-12 13:11 
GeneralRe: DAO Framework Pin
HuntrCkr7-Feb-12 17:36
HuntrCkr7-Feb-12 17:36 
GeneralRe: DAO Framework Pin
Florin Jurcovici7-Feb-12 21:46
Florin Jurcovici7-Feb-12 21:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.