Wednesday, 27 July 2016

Search Multi Columns or Individual....SQL

Useful bit of SQL for when Searching and wanting to have the avility to search certain columns.....


DECLARE @searchstring VARCHAR(100) = ''

SET @searchstring = 'fire'

DECLARE @CheckCol1 BIT = 1
DECLARE @CheckCol2 BIT = 0
DECLARE @CheckCol3 BIT = 0

SELECT *
FROM (
SELECT 'Fire' AS Col1, 'Hot' AS Col2, 'Heat' AS Col3
UNION ALL
SELECT 'Ice', 'Cold', 'Freeze'
) TBL
WHERE CONCAT (
'|'
, (
CASE
WHEN @CheckCol1 = 1
THEN TBL.Col1
ELSE ''
END
)
, (
CASE
WHEN @CheckCol2 = 1
THEN TBL.Col2
ELSE ''
END
)
, (
CASE
WHEN @CheckCol3 = 1
THEN TBL.Col3
ELSE ''
END
)

) LIKE '%' + @searchstring + '%'

Wednesday, 26 September 2012

Skip Over OnTimer_Tick Event C#

Something that was starting to frustrate me when debugging a project was the OnTimer_Tick event that kept taking the focus when stepping through the code. (F11) or (F10). 


But by referencing 


System.Diagnostics 

You can place this tag above the event and it wont step into this event when the code is debugging.

[DebuggerHiddenAttribute]

 As I will demonstrate below.
Code Snippet
  1. #region[Event] – Timer1Tick(xxx,xxx)
  2. ///<summary>
  3. /// When Timer1 ticks.
  4. ///</summary>
  5. ///<param name=”sender”>The sender.</param>
  6. ///<param name=”e”>The <see cref=”System.EventArgs”/> instance containing the event data.</param>
  7. [DebuggerHiddenAttribute]
  8. private void Timer1Tick(object sender,
  9. EventArgs e)
  10. {
  11. // get the current process
  12. long totalBytesOfMemoryUsed;
  13. using (Process currentProcess = Process.GetCurrentProcess())
  14. {
  15. totalBytesOfMemoryUsed = currentProcess.WorkingSet64;
  16. }
  17. toolStripStatusLabel1.Text = string.Format(“Current Memory Usage {0} MB”,
  18. ((totalBytesOfMemoryUsed / 1024) / 1024));
  19. }
  20. #endregion

I just wanted to post this, just in case it helps someone else one day!