Wednesday, October 14, 2015

Reality

There were some people moving furniture from a house. The neighbors saw them, and thought that may be there neighbor is moving to another place.
After they left, the police came. And started asking "did you see the thief?". 

Elections looked fine, until people started coming up with the problems that they faced. So if someone stole my vote, i have to say it. Even if its the 100th time. I will not let any one steal and get away with it. Don't tell me that you shouted last time too. 

Sunday, March 08, 2015

Recursive Function in SQL Query


What i wanted to do was to make a function that will give me all the people under 1 manager.
So there could be managers under 1 manager ans so on.

This is what i did.

alter FUNCTION fGetManager
(     
       @EmployeeID bigint
)
RETURNS TABLE
AS
RETURN
(
WITH DR ( KID, NAME, Manager) AS (
SELECT KID, NAME, Manager FROM Employees K WHERE KID = @EmployeeID
UNION ALL
SELECT K.KID, K.NAME, K.Manager FROM Employees K INNER JOIN DR D ON K.Manager= D.KID
)
SELECT kid FROM DR
)
GO


--Using this function

--SELECT * FROM Employees where kid in ( select * from [dbo].[fGetManager] (2))

Enjoy IT!

Monday, January 20, 2014

Select Random Rows from SQL Server DB Table


Wanted to select random rows from a table for some analysis. Found this.

 SELECT * FROM TABLENAME
  WHERE (ABS(CAST(
  (BINARY_CHECKSUM
  (COLUMNNAME, NEWID())) as int))
  % 100) < 1

Sunday, November 18, 2012

Convert Column names to Captions

I wanted to convert a column name from the database to a caption.
E.g:
DBType  to "DB Type"
ApplicationURL to "Application URL"
This is what i did for it.
C# code

public static string ReturnColumnCaption(String f)
        {
            string s = "";
            char o = '\0';
            for (int i = 0; i <= f.Trim().Length - 1; i++)
            {
                char c = f.Substring(i, 1)[0];
                if (char.IsUpper(c))
                {
                    if (char.IsUpper(o))
                    {
                        if (i + 1 < f.Trim().Length)
                        {
                            char t = f.Substring(i + 1, 1)[0];
                            if (char.IsUpper(t))
                            {
                                s += c;
                            }
                            else
                            {
                                s += " " + c;
                            }
                        }
                        else
                        {
                            s += c;
                        }
                    }
                    else
                    {
                        s += " " + c;
                    }

                }
                else
                {
                    s += c;
                }
                o = c;
            }
            return s.Trim();
        }

VB.NET
Private Function ReturnColumnCaption(ByVal f As String) As String

        Dim s As String = ""
        Dim o As String = ""
        For i As Integer = 0 To f.Trim.Length - 1
            Dim c As Char = f.Substring(i, 1)
            If Char.IsUpper(c) Then
                If Char.IsUpper(o) Then
                    If i + 1 < f.Trim.Length Then
                        Dim t As Char = f.Substring(i + 1, 1)
                        If Char.IsUpper(t) Then
                            s += c
                        Else
                            s += " " + c
                        End If
                    Else
                        s += c
                    End If
                Else
                    s += " " + c
                End If

            Else
                s += c
            End If
            o = c
        Next
        Return s.Trim()
    End Function

Tuesday, July 17, 2012

Delete duplicate records Query

Found this query to delete duplicate records from a table. Very small query, but if table is big then it will take some time. But works

[code]


DELETE FROM [Table1
WHERE  Table1ID NOT IN SELECT MAX( Table1ID)  
FROM [ Table1GROUP BY [Col1] ,[ Col2] ,[ Col3)


[/code]

Enjoy IT!

Wednesday, May 16, 2012

Gadget Style WPF Application

I just made this from a Channel 9 Training Video.

XAML:
Type Here

Code Behind:
Class Window1

Private Sub Window1_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.MouseLeftButtonDown
Me.DragMove()
End Sub

Private Sub CloseButton_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles CloseButton.Click
Me.Close()
End Sub
End Class

Delete entire SharePoint List Items (VB.NET)


A small problem that i faced, was to delete an entire SPList Items.
Here is the solution.

'Get Context
Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
'Open Web
Dim wb As SPWeb = siteCollection.OpenWeb()
'Get List
Dim spl As SPList = wb.GetList(wb.Url.ToString + "/Lists/YourListNameToDeleteItems")
spl.AllowDeletion = True
Try
    While spl.Items.Count > 0
        spl.Items(0).Delete()
    End While
    spl.Update()
'"Update Delete for list items"
Catch ex As Exception
End Try

Tuesday, November 09, 2010

Blooper on Google Fast Flip

Just check the link, Google FastFlip has a blooper.

What happened actually (in my opinion) is that Google has an application that opens URL and takes pictures of the desktop and saves them in there fastflip. So in this blooper the website gave a popup, and as Machine is a Machine even though it was a computer with an application running on it.

This blooper is of News mentioned below.
Technology Review by Lauren Gravitz in Sci/Tech

And page is 7th, so you have to go right 7 times.


Enjoy IT ;)