Search This Blog

Thursday, February 13, 2014

sys.data_spaces SQL Server

SQL Server > Catalog Views > sys.data_spaces

Return info for each data space.

Example

select * from sys.data_spaces






Add Image Column to Telerik Radgrid

Telerik > RadGridView > GridViewImageColumn

GridViewImageColumn displays read-only images for database columns of image data





GridViewImageColumn imageColumn = new GridViewImageColumn();
imageColumn.Name = "imgCol";
imageColumn.FieldName = "dbPhoto";
imageColumn.HeaderText = "Picture";
imageColumn.ImageLayout = ImageLayout.Zoom; // Zoom - Image is zoomed but the aspect ratio is preserved:
radGridView1.MasterTemplate.Columns.Insert(3, imageColumn);




Using Joins SQL Server Examples

SQL SERVER > QUERY > JOIN

Using joins you can retrieve data from two or more tables based on logical relationships between the tables.

create table #category(name varchar(20), description  varchar(20))

insert into #category(name,description)
values('cat 1','cat 1 description')
insert into #category(name,description)
values('cat 2','cat 2 description')
insert into #category(name,description)
values('cat 3','cat 3 description')

create table #product(id int, name varchar(20), category varchar(20))

insert into #product(id,name,category)
values(1,'product 1','cat 1')
insert into #product(id,name,category)
values(2,'product 2','cat 2')
insert into #product(id,name,category)
values(2,'product 3',null)






INNER JOIN  returns all the columns in both tables, and returns only the rows for which there is an equal value in the join column. 

select p.id, p.name, c.description as category
from #product p
inner join #category c
       on p.category = c.name


LEFT OUTER JOIN includes all rows in the a table  whether or not there is a match on the another table.

select p.id, p.name, c.description as category
from #product p
left  join #category c
       on p.category = c.name







RIGHT OUTER JOIN indicates all rows in the second table are to be included in the results, regardless of whether there is matching data in the first table.


select p.id, p.name, c.description as category
from #product p
right  join #category c
       on p.category = c.name




FULL OUTER JOIN includes all rows from both tables, regardless of whether or not the other table has a matching value.
select p.id, p.name, c.description as category
from #product p
full  join #category c
       on p.category = c.name







CROSS JOIN produces the Cartesian product of the tables involved in the join.
 
select p.id, p.name, c.description as category
from #product p
cross join #category c

      


drop table #product
drop table #category

ABS SQL Server Example

SQL Server > Built-in Functions > ABS

Returns the absolute positive value of a numeric expression.

Example

DECLARE @i int;
SET @i = -333;
SELECT ABS(@i);

Result:
333


 
 





Power SQL Server Example

SQL Server > Built-in Functions > POWER

Returns the value of a number to the specified power.

Example:

select power(2,4)

Result:

16
 
 






Wednesday, February 12, 2014

ORA_ROWSCN Oracle example

Oracle

ORA_ROWSCN returns the conservative upper bound system change number (SCN) of the most recent change to the row. This is useful for determining approximately when a row was last updated.

Example

Get the system change number of the last operation on the items table

SELECT ORA_ROWSCN, item_name FROM items WHERE item_id = 10;




Friday, February 7, 2014

Convert binary data to MemoryStream C#

C# > IO > MemoryStream

Creates a stream whose backing store is memory.

Example:

Convert binary data to MemoryStream

public MemoryStream GetMemoryFile(System.Data.Linq.Binary image)
{   
   return new MemoryStream(image.ToArray());
}