Mar 4, 2008

Passing Data from one sp to other sp using Temp Table.

Passing Data from one sp to other sp using Temp Table.

 

Hi,

Here I tried a trick, there may be others trick also to do the same.

 

 

CREATE PROCEDURE Proc_Record_Insertion

AS

-- This #Temp1 table is defined in the other sp which I am using here.

INSERT INTO #Temp1(id,info) VALUES(1,'Mohammad')

INSERT INTO #Temp1(id,info) VALUES(2,'Irfan');

INSERT INTO #Temp1(id,info) VALUES(3,'matespoint@gmail.com');

INSERT INTO #Temp1(id,info) VALUES(4,'matespoint.blogspot.com');

GO

-- This will create a sp Proc_TempTableCreate which create a Temp table and insert four recors into it.

 

CREATE PROCEDURE Proc_UseTempData

AS

BEGIN

CREATE TABLE #Temp1

            (id int,

             info varchar(40) )

 

-- Executing the sp

EXEC Proc_Record_Insertion

 

SELECT * FROM #Temp1

END

Reading URL thru HttpRequest in C#

Here is the sample code for reading Http request.

 

HttpWebRequest request = null;

   string url = “http://matespoint.blogspot.com”

   // Create web request

   request = (HttpWebRequest)WebRequest.Create(url);

   // Set value for request headers

   request.Method = "GET";

   request.ProtocolVersion = HttpVersion.Version11;

   request.AllowAutoRedirect = false;

   request.Accept = "*/*";

   request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";

   request.Headers.Add("Accept-Language", "en-us");

   request.KeepAlive = true;

 

   StreamReader responseStream = null;

   HttpWebResponse webResponse = null;

   string webResponseStream = string.Empty;

   // Get response for http web request

   webResponse = (HttpWebResponse)request.GetResponse();

   responseStream = new StreamReader(webResponse.GetResponseStream());

 

// Read web response into string

   webResponseStream = responseStream.ReadToEnd();

 

Mar 3, 2008

IF EXIST Vs COUNT(*) - SQL Server

IF EXIST Vs COUNT(*)

 

Many times we see that people use count(*) to get the condition that if we have any record like

IF (SELECT COUNT(*) FROM Employee where Salaried =0 ) >0

BEGIN

PRINT 'Yes Got It'

-- Do your calculation here.

END

 

We are doing some calculation if we get Salaried=0 for at least once. And I know many times we use the same trick.

"The cost for getting the count(*) is that it counts all the data we get by where clause."

Use if exist to reduce this overhead.

IF EXISTS(SELECT * FROM Employee where Salaried =0)

BEGIN

PRINT 'Yes Get it'

-- Do your calculation here.

END

 

In this as soon as we get the first record further execution stops and it comes out of the if condition with true. If this not get any result then will cost same as above query.

 

Feb 25, 2008

Uses of GO in SQL

Very interesting question, can anybody what will be the answer if we execute this query by selecting all at once.

 

DECLARE @Test1 int, @Test2 VARCHAR(20)

SET @Test1 = 1;

SET @Test2 = 'Character';

SELECT @Test1,@Test2

GO

SELECT @Test1,@Test2

 

-       Either it through an error

-       Or Give 1 Character twice.

 

Yes – It will through error as @Test1 is undefined, because after GO it ends the scope of declaration of the variable.

Here we seen the scope of Variable declaring into SQL.

 

 

Feb 22, 2008

Getting all columns for a Table

Using INFORMATION_SCHEMA View

 

Getting all columns for a Table

SELECT * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '<TABLE NAME>'

 

Getting all constraints for a Table

SELECT * FROM  INFORMATION_SCHEMA.TABLE_CONSTRAINTS where TABLE_NAME = '<TABLE NAME>'

 

Getting all check constraints for a Table

 

SELECT * FROM INFORMATION_SCHEMA.CHECK_CONSTRAINTS where CONSTRAINT_NAME IN (SELECT CONSTRAINT_NAME FROM  INFORMATION_SCHEMA.TABLE_CONSTRAINTS where TABLE_NAME = '<TABLE NAME>')

 

 

For more about INFORMATION_SCHEMA please visit (However this link is a kb for a bug still has enough pointers to go ahead)

http://support.microsoft.com/kb/294350

 

Happy learning

Feb 20, 2008

SilverLight 1.1 MediaElement Example

Here are the links for SilverLight 1.1 MediaElement example.

Nice links to get hands on SilverLight 1.1

 

http://blogs.msdn.com/coding4fun/archive/2008/01/22/7163484.aspx

http://www.codeproject.com/KB/silverlight/SLFun.aspx

 

Do it and Have fun!

 

 

Mediaelement not showing the media.

SilverLight 1.1 Media element not showing the media.

Mediaelement not working with my case, but may be these links will help in your case.

http://silverlight.net/forums/p/1532/8690.aspx#8690

http://silverlight.net/forums/t/2914.aspx

I am using like

<MediaElement Width="400" Height="300" Canvas.Left="10" Canvas.Top ="10" Source="viz.wmv" AutoPlay="True"/>

It don’t showing any error but not showing the video also.

When I tried using http://sever/viz.wmv its giving download error ErrorType: 1001

Trying to get what may be the reason.

After a lot of hard work I get the problem.

The video file I was using having some problem, however this was working with media file. Funny na ?? So let check with other media file also, if you are facing the same problem.

SQL - Difference between CAST,CONVERT and PARSE

TODO---