Posts

Week Number from date in .Net

Hello friends, I will show an example that find out week no. from date in VB.net. Step 1: Imports System.Globalization in your page. Step 2 : Now in your Page_load event of default.aspx page,paste the following code Dim ciCurr As CultureInfo = Nothing Dim intweekNo As Integer = 0 Dim intCalendarWeekRule = 0 Dim dteDate as DateTime=Now.Date Try ciCurr = CultureInfo.CurrentCulture intweekNo = ciCurr.Calendar.GetWeekOfYear(dteDate, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) lblOutput.Text=intweekNo.ToString() Catch ex As Exception lblMessage.Text=ex.Message Finally End Try Step:3 When you run the following code you will get the weekno. of current date.

How to Use Not IN operator

Hello Friends Here i am explaining an example of NOT IN operator. Suppose you have two tables one is employee and Bademployee employee and Bademployee has relationship. Bademployee contains records who are bad Now you want to show the Good employee so following is the example Step : 1 create Table emp Run this Query in your Query Analyzer for table emp 1) CREATE TABLE [dbo].[emp]( [empId] [int] NOT NULL, [empName] [nvarchar](max) NULL, CONSTRAINT [PK_emp] PRIMARY KEY CLUSTERED ( [empId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] Now Run this Query in your Query Analyzer for table bademp CREATE TABLE [dbo].[bademp]( [empid] [int] NOT NULL, [bademp] [nvarchar](50) NOT NULL, CONSTRAINT [PK_bademp] PRIMARY KEY CLUSTERED ( [empid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY...

Examples of Self JOIN

Hello friends, Self Join is very basic thing in SQL.I am explaining it with example in SQL Server Enjoy Self JOIN Step 1 :Create a table named as employee Run the following Query CREATE TABLE [dbo].[employee]( [empId] [int] NOT NULL, [empname] [nvarchar](1200) NOT NULL, [managerid] [int] NOT NULL ) ON [PRIMARY] Step 2 : Insert data into it Insert into employee values (1,'john',1) Insert into employee values (2,'Jasmine',1) Insert into employee values (3,'Rahman',2) Insert into employee values (4,'Victor',3) Insert into employee values (5,'Majid',1) Insert into employee values (6,'Olvin',3) Insert into employee values (7,'Soniya',2) step 3 : Now ,I want the records of employees with thier manager Id and manager name so I will apply Self JOIN on employee table on empId and managerId. Check and run this Query SELECT a.empid,a.empname as EmployeeName,a.managerid as ManagerId,b.empName as ManagerName FROM employee a INNER JOIN...

Append Characters to Left of any String -- Use of PadLeft function

Hello everyone ! I heard the function of padLeft,padright in my college.I thought , what is the need of this function, where we used it.I skip this function and called it "useless". but at the time of programming in VS.Net , i got a issue that is To append zeros at left side of a string say "61" and its should be 10 digit string like that "0000000061" then, I start coding ,try to applying "***for if,,,,while & logic****** Select Case**** ". Result : Partially successful , but code was not feasible,reliable....in short.. fail ! Then, while solving the online practice test ,i got the questions of padleft .I was clueless,and remember my carelessness. I got a clue from that test,also got an idea that i can use this function for appending any character to a string at right side or left side of it. So suppose you have string say "61", and you want make it 10 digits string, with zero's at leftside then use padleft function. st...

Check Type of Object at Runtime in C#

If You want to check the TYPE of an object at runtime in C# then you have to use IS Keyword example : using System; class CApp { public static void Main() { string s = "Shubhank"; long i = 900; Console.WriteLine( "{0} is {1}an integer", s, (IsIntegerType(s) ? "" : "not ") ); Console.WriteLine( "{0} is {1}an integer", i, (IsIntegerType(i) ? "" : "not ") ); } static bool IsIntegerType( object obj ) { if( obj is int || obj is long ) return true; else return false; } } Output will be Shubhank is not an integer 900 is an integer

Find nth Highest Salary from Employee Table

How to Find 2nd ,3rd or upto....Nth highest Salary of any employee in SQl Step 1 Create Table Create Table emp ( empName nvarchar(max), Salary int ) Step 2 Insert records 1 ) Insert into values emp ('John',2000) 2 ) Insert into values emp ('Kim',5000) 3 ) Insert into values emp ('Walter',1500) 4 ) Insert into values emp ('Obama',3000) 5 ) Insert into values emp ('John Vincet',2500) 6 ) Insert into values emp ('Womek',3500) Step 3 Query Find the 2nd Highest Salary from emp Table Select * from emp a Where (2=(Select Count(Distinct b.Salary) from emp b Where b.Salary >= a.Salary)) Step 4 Execute the Step 3 Query Step 5 For find the nth Highest Salary from emp Table Select * from emp a Where (n=(Select Distinct(b.Salary) from emp b Where b.Salary >= a.Salary)) Step 6 Check the Ouptut..

String Function in SQL-Substring,Reverse,CharIndex

Suppose You have String "~/ABC/PQR.xxx" in your tables Now u Want to string PQR.xxx fromm above string So For That Follow the Steps 1) Open NewQuery Window 2) Paste following Code declare @str as varchar(200),@str1 as varchar(200),@rev as varchar(200) set @str ='~/ABC/PQR.xxx' select @rev = reverse(@str) SELECT @str1 = CHARINDEX('/', reverse(@str)) select @str1,@rev'@rev',reverse(substring(@rev,0,convert(int,@str1))) 3) Execute the Code 4) You will get the Output Like that PQR.xxx