Category: Uncategorized

Oct 27 2017

To map each bit in a single byte to individual bools do this (using c#)

Implemented as two extension methods in this example. Using an enum to get the bit your looking for.

public enum Weekday
{
    Sunday=7,
    Monday=6,
    Tuesday=5,
    Wednesday=4,
    Thursday=3,
    Friday=2,
    Saturday=1
}

public static bool GetBitwiseBool(this byte bits, Weekday weekday)
{
	return (bits & (1 << (int)weekday - 1)) != 0; 
} 

public static bool GetBitwiseBool(this string bits, Weekday weekday) 
{ 
    if (!bits.All(c=>"01".Contains(c)))
	{
		bits = "11111111";
	}
	
	//8 character or less
	if (bits.Length>8)
	{
		bits = bits.PadLeft(8,'0');
	}

	var myByte = Convert.ToByte(bits, 2);
	return myByte.GetBitwiseBool(weekday);
}

Aug 30 2017

Comment by Seth Spearman on Understanding the recursive CTE termination check

I'll have to check out that dense_rank() function. But thanks...awesome solution.
Aug 30 2017

Comment by Seth Spearman on Understanding the recursive CTE termination check

@scsimon, thanks for your answer. My question lacked context. I have edited the answer to provide some context. I intentionally left my sqlfiddle very simple so that the recursion question could be addressed. My real query actually does have some depth to it.
Jun 23 2017

Comment by Seth Spearman on Does Mirth Open-Source support channels that work over https (using ssl)

Can you point me to a URL that explains the workaround?
Apr 19 2017

Answer by Seth Spearman for MS Access tabbed form multiple OnCurrent firings

I believe the proper way to do this is to not dynamically change the rowsource of the combobox. Instead, set the rowsource to a query using the query designer and have the query read the value from the "main form" just as is shown in your sample code...Forms![products main form]!ProductNumber.

Then I would trigger the refresh of the combo box using the MAIN FORMs AfterUpdate event. It will be something like MainForm!MySubForm.Form("mycombobox").requery. (I may not have that syntax exactly right...my access syntax is rusty.)

BTW, I don't like my own answer. The reason is that you are hard-coding a dependency between the subform and its parent. That might be fine if you will NEVER use that subform anywhere else. To get around this some Access Developers use a hidden form that has textboxes that you set from the Main Form's After Update event. Then the query is updated to refer to the the hidden form's textbox that you created for this form.

There are other ways to do this, too (public functions for example). But sorry, that is not really what you were asking for. My first method will work. But first time you need to re-use that subform you will need to refactor and the hidden form solution works pretty well.

Feb 22 2017

If you need to make a bootable USB drive using an ISO…

…use Rufus

http://rufus.akeo.ie/

Nov 09 2016

Comment by on Is there a way to aggregate a variable range of dates in SQL using a SET operation

Wow...this totally worked! I love the simplicity. No need to avoid holidays so I am giving you the answer.
Nov 08 2016

Comment by on Is there a way to aggregate a variable range of dates in SQL using a SET operation

@Hogan I see your point.
Oct 18 2016

Does SQL short-circuit the evaluation of an OR in the WHERE CLAUSE?

Looking at other questions here on SO and google seems to indicate MS Sql Server does not guarantee to short circuit the expressions in the WHERE clause.

Does that mean that a WHERE expression like this this one cannot be trusted to work...?

... WHERE (@include_voided = 1 OR mytable.void = 0) AND ... 

I frequently use this kind of expression in my stored procedures. Having researched short-circuiting for another reason I am now wondering if this should be replaced with ...

... WHERE mytable.void = case when @include_voided=1 then mytable.void else 0 END

...as all of the articles seem to indicate that CASE statements are the only ones guaranteed to short-circuit.

I am hoping that the first expression is fine just because it is more readable and easier to type.

Sep 15 2016

How to add an SQL Table to a Microsoft Access application

I was having a weird time getting a new Sql Table to work properly in an Access application.  The problem is that this app has not had a new table added for several years so I kept chasing red herrings.  Ultimately here are the steps that work for me…

 

WHAT TO DO TO ADD AN A TABLE TO Sql

1.  Be sure to NOT forget to set the permissions on the table like this…
    GRANT INSERT, UPDATE, DELETE, SELECT, VIEW DEFINITION ON <NEW_TABLE_NAME> TO MYDB  Ultimately this was the step I forgot.
    
    DO NOT link the table to Access until the permissions have been set.

2.  When adding the table as a new linked table into  the app, use a FILE DSN.  Using a System DSN may have contributed to the issue as well.  Click the Save Password checkbox when linking it in.
   
3.  Remove the dbo_ from the front of the table name in Access.

4.  Your Access app needs a RefreshTableLinks process as described all over the place (just google refresh sql table links in msaccess).  Run that after adding the table.  Here is an example. 

http://stackoverflow.com/questions/564265/how-to-refresh-linked-tables-in-an-access-mdb-when-odbc-changes