Sunday, 6 November 2011

Common SQL Solutions



1)insert one table into other directly in sql

insert into tbl_Processing (Process_ID,ArrivalId,Adate,BoxDesignId,Qty,Rate,Total) SELECT   Process_ID,ArrivalId,Adate,BoxDesign,Qty,Rate,TotalBoxAmount FROM  temp_BoxProcessing


2)UNION two table
select * from(select * from TrainingSessionSummerTrainView  union select * from TrainingSessionIndusView )a where orgfu_org_name=1

3) Versions error
Unfortunatly it is due to old version of sql eg.2000

 and you are trying to implement something which was not available on that time...
leave it whatever it was the solution is
just replace [dbo] from your table even [ ] these brackets from your table name
(its a solution for one of its kind,you may have other prob.,let me know if any)


ask me if any further question you have...

4)Date differences in SQL


SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(getDate())-1),getDate()),101)



5)Create New Table (A CLONE COPY OF EXISTING TABLE)

SELECT   * 
INTO           New_Table
FROM         Exisiting_Table

6)What to Show When There Is NO Value returning in row?

suppose the query is ...

select price from tableproduct where id='123'


and there is no id with 123
then you will get a single row in result with NULL

but you further need some calculation with this output so just make NULL to 0 by this query...

select MAX(isnull(pattern,0)) from tbl_rueno where pi_no='1111'

 but be careful if the data type of the selected field is non int,
you should make column data type any datatype to int,so we did bit modification below to do so...


MAX(isnull(convert(int,crate_to),0))+1 from tbl_rueno where pi_no='1111'






1 comment:

  1. vijay could you post all short solution in just one page,your solutions are very mean full for me while i am in programming.

    ReplyDelete

Print Only Grid View in ASP.net

ASP.net How to Print Only GridView < div id ="gridviewDiv" >   < asp:GridView ID ="gridViewToPri...