Friday 27 December 2013

SQL SERVER Query

select max(a) from
(
Select
(
  SELECT Max(v)
     FROM (VALUES (Theatre), (ClassRoom), (UShape),(Cabaret),(
DinnerDance),(Reception))
   AS value(v))as a
FROM PropertyMeetingRoom
)t

Monday 10 June 2013

How to check string is number or not in C#

 Some time we have required to check the value of string is Number or not if it no then offcourse       our   task on these like sum, avg, max etc etc but somehow it contain string value is not Numeric then its panic . Then what is the solution
Simply check the no if it is numeric then perform the action other wise no action performed.

Below is the simple example .
there are a method in C# which check the datavalue. Method name is TryParse
it returns always boolean value. 

Solution :

string strValue = "ABC";
double Num;
bool isNum = double.TryParse(Str, out Num); // out parameter are used
if (isNum)
Response.Write(Num.ToString());  // you use here your label id or other thing
else
Response.Write("Invalid number");
  // you use here your label id or other thing 

Friday 31 May 2013

How to get all table name dependent on any column in SQl Server

Query for this is

SELECT o.Name as Table_Name , c.Name as Field_Name, t.Name as Data_Type
, t.length as Length_Size
FROM syscolumns c
     INNER JOIN sysobjects o ON o.id = c.id
     LEFT JOIN  systypes t on t.xtype = c.xtype 
WHERE o.type = 'U'  and c.name like '%country%'
ORDER BY o.Name, c.Name

here red color name is your required column name .

Thursday 7 March 2013

Select Query in SQL Server


Hi all
I have a Question for   you .
I have one table with two columns a and b
like this
Create table  test(
a varchar(10),
b varchar(10)
)

After that i execute a query

select  a b  from test

Then my question is   what will be  the output of this simple query .
 

Friday 18 January 2013

Difference between === and == in javascript

if(1=="1")
{
alert("hello");
}else
{
alert("hi");
}

Some time question arises that what is the output.
what you think about this ?
of course your answer is hello .
But now can you guess what is the result of following code

if(1==="1")
{

alert("hello");
}else
{
alert("hi");
}
bit confusing .
answer is hi .
It is becuase the expreesion === to compare datatype as well as value .




Monday 17 December 2012

How to start Visual Studio from run prompt

Hi  friends some time question arise that how to open visual studio from run command so there are the solution.
there are some simple step to complete this task

Step -1 
open the run prompt like this
Start->Programs->Run
or
press 
window logo + R 
then below pop up open
Step -2
after that type on this run prompt 
devenv
or
devenv /nosplash 
 
 after that press enter. then your visual studio open .
there are difference in both keyword 
devenv for Opens Visual Studio  With Splash Screen.
 devenv /nosplash for Opens Visual Studio  Without Splash Screen. 
now the question arise that what is Splash screen 
when you type only devenv on run prompt then below screen are shown

if you are type devenv /nosplash  then this screen are not shown.
devenv /nosplash this command is faster than devenv

Hope this will help you ..
if any issue then please let me know
Thanks 
ROHIT KUMAR SRIVASTAVA

Friday 14 December 2012

Advantage and disadvantage of Juqery

Advantage-
  • Good User Experience, close to a Windows GUI
  • Much easier to use than plain JavaScript
  • Impressive speed
  • Coders don’t have to worry about Browser differences
  • Reduces Server Load as fewer round-trips
  • Widely used, good community support
  • Many components already developed
  • Open Source

Tuesday 30 October 2012

Delete duplicate record in SQL SERVER

Question :- Some time the question arise that how to delete duplicate record from table ?

Answer : firstly we create the table 

CREATE TABLE tblemployee1(
    [empid] int identity(1,1) NOT NULL,
    [empname] [varchar](10) NULL,
    [mgrid] [varchar](10) NULL,
    [test] [varchar](100) NULL)


insert some data on this  like below

insert into tblemployee1 values('Cherry',1,'Useful')
insert into tblemployee1 values('Cherry',1,'Useful')
insert into tblemployee1 values('Cherry',1,'Useful')
insert into tblemployee1 values('Rohit',2,'Useless')
insert into tblemployee1 values('Rohit',3,'Useless')
insert into tblemployee1 values('Usertest',3,'test')
insert into tblemployee1 values('Usertest',3,'test')

Select * from tblemployee1

output is

empid    empname    mgrid         test
1            Cherry          1             Useful
2            Cherry          1             Useful
3            Cherry          1             Useful
4            Cherry          1             Useful
5            Cherry          1             Useful
6            Rohit            2             Useless
7            Rohit            3             Useless
8            Usertest       3              test
9            Usertest       3              test


now we waana to delete the duplicate record which is with name  

the query is  
  
;with cte as(
Select ROw_number() over(partition by empname   order by empname) as col ,* from tblemployee1)
delete from  cte where col>1


then the ouput is

empid    empname    mgrid    test
1              Cherry          1          Useful
6              Rohit            2          Useless
8              Usertest       3          test 


here we use the rownumber for deletion with COMMON TABULAR EXPRESSION.

Hope this will help you 

if any issue then please let me know

Thanks 
ROHIT KUMAR SRIVASTAVA

 

Monday 29 October 2012

Change Color of Status Bar in SQL SERVER

Some time when we work on multiple SQL SERVER then we are confused in which database we have to upload the data or execute the query so we are see the server name or scroll up down to check is it right server or not.
the best solution is if in this there are color combinatin then we are easily identfy this .
here is the solution in SQL SERVER 2008
Click on options>> then new window open





after that click on select button then new popup open






after that

after that select any color than OK .After that open the new window your task pane color is change
You set the different color for different SQLSERVER.

ROHIT KUMAR SRIVASTAVA



How can I quickly identify most recently modified stored procedures or table in SQL Server


1. Select * From sys.objects where type='u' and modify_date between GETDATE()-1 and GETDATE()

Note :  use p for store procedure,tr for trigger and fn for function

OR
2. Select * From sys.objects where type='u' order by modify_date desc

Note :  use p for store procedure,tr for trigger and fn for function

you change the date accodingly in first Query
use type='p' for storeprocedure in this Query



ROHIT SRIVASTAVA