Click here to Skip to main content

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, embarrasing 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: for(int i=0; i<size; i++) PinmemberAntonino Porcino1-May-13 6:03 
GeneralRe: for(int i=0; i<size; i++) PinmemberRafagaX1-May-13 7:38 
GeneralRe: for(int i=0; i<size; i++) PinmemberCarlosian2-May-13 5:36 
GeneralRe: for(int i=0; i<size; i++) PinmemberMember 100271053-May-13 7:15 
GeneralRe: for(int i=0; i<size; i++) Pinmemberrobocodeboy6-May-13 0:27 
GeneralRe: for(int i=0; i<size; i++) PinmemberNicolas Dorier4-May-13 22:37 
GeneralRe: for(int i=0; i<size; i++) Pinmemberpeterchen6-May-13 3:58 
GeneralRe: for(int i=0; i<size; i++) PinmemberDanielSheets6-May-13 8:12 
GeneralRe: for(int i=0; i<size; i++) PinmemberDerekTP1238-May-13 1:26 
Generalwhile(life!=death) PinmemberBikash Prakash Dash11-May-13 6:03 
GeneralRe: for(int i=0; i<size; i++) PinmemberPeterTheSwede20-May-13 0:58 
GeneralRe: for(int i=0; i<size; i++) PinmemberJohn Hunley29-May-13 9:46 
GeneralRe: for(int i=0; i<size; i++) PinmemberBCantor31-May-13 10:54 
GeneralInteresting Observation Pinmembervirang_2129-Apr-13 15:45 
I was looking at one old SQL stored proc and found this strange behaviour.
 
 
DECLARE @Scrap_Qty int
DECLARE @FilledQty int
SET @Scrap_Qty=10 --Change this to 1 and it still run
SET @FilledQty = 2
 
BEGIN
 
IF @Scrap_Qty  > @FilledQty
 declare @currDate varchar(10)   
 Set @currDate= Convert(VARCHAR(10),GetDate(),103)  
 PRINT @currDate
 
END  
 
 
Look at the if condition .. it does not have BEGIN..END... To make thing interesting weather if condition is true or false you will get the output for parameter @currDate
 
If I add PRINT @Scrap_Qty right after IF and run it again it will only print value for @Scrap_Qty if condition is true. Which leads to question why sql is not complaining about undeclared variable if @Scrap_Qty is less than @FilledQty ?
 
I would have assumed if condition without BEGIN .. END block will behave like a normal one line to execute if condition is true which in above block is declaration of @currDate variable.
 
DECLARE @Scrap_Qty int
DECLARE @FilledQty int
SET @Scrap_Qty=10 --Change this to 1 and it won't output @Scrap_Qty
SET @FilledQty = 2
 
BEGIN
 
IF @Scrap_Qty  > @FilledQty
	PRINT @Scrap_Qty
 declare @currDate varchar(10)   
 Set @currDate= Convert(VARCHAR(10),GetDate(),103)  
 PRINT @currDate
 
END  
Zen and the art of software maintenance : rm -rf *
 
Math is like love : a simple idea but it can get complicated.

GeneralRe: Interesting Observation PinmemberPablo Aliskevicius29-Apr-13 20:47 
GeneralRe: Interesting Observation Pinmemberagolddog1-May-13 4:42 
GeneralRe: Interesting Observation PinprofessionalRaja Sekhar S5-Jun-13 22:14 
GeneralRe: Interesting Observation PinmemberPablo Aliskevicius5-Jun-13 22:21 
GeneralRe: Interesting Observation PinprofessionalRaja Sekhar S5-Jun-13 23:05 
GeneralRe: Interesting Observation PinmemberPablo Aliskevicius6-Jun-13 0:31 
GeneralRe: Interesting Observation PinprofessionalRaja Sekhar S6-Jun-13 0:39 
GeneralNot 'Clap' but 'CLAP', dammit. [modified] PinmemberBrady Kelly24-Apr-13 23:36 
GeneralRe: Not 'Clap' but 'CLAP', dammit. [modified] Pinmemberdusty_dex25-Apr-13 0:19 
GeneralRe: Not 'Clap' but 'CLAP', dammit. PinmemberBrady Kelly25-Apr-13 0:33 
GeneralRe: Not 'Clap' but 'CLAP', dammit. PinmemberH.Brydon25-Apr-13 15:59 
GeneralRe: Not 'Clap' but 'CLAP', dammit. PinprofessionalBrisingr Aerowing25-Apr-13 2:16 
GeneralRe: Not 'Clap' but 'CLAP', dammit. PinmemberBrady Kelly25-Apr-13 3:56 
GeneralRe: Not 'Clap' but 'CLAP', dammit. Pinmemberhvanzyll26-Apr-13 6:26 
GeneralRe: Not 'Clap' but 'CLAP', dammit. PinmemberRob Grainger1-May-13 4:23 
GeneralProduction code adds a BCC to email account of developer Pinmember0bx24-Apr-13 6:48 
AnswerRe: Production code adds a BCC to email account of developer PinprotectorAspDotNetDev24-Apr-13 6:54 
GeneralRe: Production code adds a BCC to email account of developer PinmemberCIDev25-Apr-13 10:17 
GeneralRe: Production code adds a BCC to email account of developer PinprotectorAspDotNetDev25-Apr-13 10:20 
GeneralRe: Production code adds a BCC to email account of developer Pinmemberagolddog26-Apr-13 4:41 
GeneralRe: Production code adds a BCC to email account of developer PinprofessionalBernhard Hiller25-Apr-13 4:54 
GeneralRe: Production code adds a BCC to email account of developer PinmemberRafagaX26-Apr-13 5:42 
GeneralNested if-else statements... Pinmember ProgramFOX23-Apr-13 8:21 
GeneralRe: Nested if-else statements... Pinmember GeekBond 23-Apr-13 8:49 
GeneralRe: Nested if-else statements... PinmvpOriginalGriff23-Apr-13 9:12 
GeneralRe: Nested if-else statements... Pinmembers_mon23-Apr-13 10:48 
GeneralRe: Nested if-else statements... PinmemberMonaco.Bavarian23-Apr-13 20:54 
GeneralRe: Nested if-else statements... PinmemberMarius ten Napel24-Apr-13 2:51 
GeneralRe: Nested if-else statements... Pinmemberryanb3124-Apr-13 3:10 
GeneralRe: Nested if-else statements... PinmemberMarius ten Napel24-Apr-13 3:36 
GeneralRe: Nested if-else statements... Pinmemberdusty_dex24-Apr-13 4:43 
GeneralRe: Nested if-else statements... PinmemberNAANsoft24-Apr-13 3:44 
GeneralRe: Nested if-else statements... PinmemberLee Chetwynd24-Apr-13 6:07 
GeneralRe: Nested if-else statements... PinmemberRafagaX24-Apr-13 6:41 
GeneralRe: Nested if-else statements... PinmembertumbledDown2earth29-Apr-13 21:32 
GeneralRe: Nested if-else statements... Pinmemberfulloflove2-May-13 18:19 

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

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


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 19 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid