Monday 15 December 2014

Get last date of month in sql SQL server






here is the solution

SELECT Dateadd(dd, -Day(Getdate()), Dateadd(mm, 1, Getdate())) 

you will get the result like














Replace  Getdate() function with your date will give you the last date that you want.


SELECT Dateadd(dd,-Day('2015/02/16'), Dateadd(mm, 1, '2015/02/16')) 


Result :

















Thank you. :)

Wednesday 3 December 2014

Get insert query from selected data in toad?





Hi,
    Now am here to tell about insert script generation from toad software. here is the steps ...


Step 1 : Write your query in editor window.





Step 2 : Click select all button in script output.














Step 3 : Right click on grid header and click Export Dataset.






















Step 4 : Select export format as Insert statement. Add output path with name. Also provide table name








































Step 5 : Click Ok button . You can get your insert statement from the path you specified.


Thank you. happy coding  :)

Monday 1 December 2014

How to update table with data from another table in Oracle?





Here is a sample code ...

UPDATE customers
SET    c_details = (SELECT contract_date
                    FROM   suppliers
                    WHERE  suppliers.supplier_name = customers.customer_name)
WHERE  customer_id < 1000; 


here customers,suppliers  are my table 


here I am going to update c_details in customers table with  contract_date in 
suppliers table with the condition suppliers.supplier_name = customers.customer_name.   

 and customer_id is less then 1000 .