I often get messed up myself when it comes to use cast and convert functions. No matter how many times I use them still I get stuck around at the basic syntax difference between the two.

So lets make it less forgetful by making them both side by side in a query and if by chance we forget, then unhesitatingly we can peek around this post.

Below is a query which shows cast and convert function in one single insert statement which I think will aid in remembering the syntax well.
Simple
insert into Book(BookId,BookTitle)Values(convert(int,'78'),''),((cast('79 as int'),'');
select * from Book

castnconvertspicy

Little Spicy with table variable
insert into Book(BookId,BookTitle)
OUTPUT
inserted.BookId,inserted.BookTitle into @tvariable(BId,BTitle)
Values(convert(int,'78'),''),((cast('79 as int'),'');

castnconvert

Hope this helps to distinguish the syntactic difference. 

The other  query where I have used Table variable is just for additional information.

For more on OUTPUT and Table variable

Advertisements