ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
WRITE A FUNCTION TO DISPLAY THE OUTPUT OF AN EXISTING TABLE 
RANGE LIKE COMMAM SEPERATED VALUES LIKE RANGE1,RANGE2,...
 Question Submitted By :: Eswar
I also faced this Question!!     Rank Answer Posted By  
 
  Re: WRITE A FUNCTION TO DISPLAY THE OUTPUT OF AN EXISTING TABLE RANGE LIKE COMMAM SEPERATED VALUES LIKE RANGE1,RANGE2,...
Answer
# 1
Create function int select_dynamic(range varchar(255)) 

As
declare
@Qry Varchar(2000) 
Begin
	Begin try
		Set @Qry =”select * from table1 where col1 
in (“+range+”)”
		Exec @qry
	Catch
		Print “error processing parameter”
		Return -1
	End try
	
Return 1
END
 
Is This Answer Correct ?    1 Yes 0 No
Carmel Franco
 
  Re: WRITE A FUNCTION TO DISPLAY THE OUTPUT OF AN EXISTING TABLE RANGE LIKE COMMAM SEPERATED VALUES LIKE RANGE1,RANGE2,...
Answer
# 2
you can write this query in table valued function

DECLARE @RangeValue As VARCHAR(MAX)
SET @RangeValue = '1,2,'

DECLARE @Qry As VARCHAR(MAX)

DECLARE @ResData AS VARCHAR(MAX)
DECLARE @InData AS VARCHAR(MAX)

DECLARE @rId AS INT
DECLARE @Pos AS INT

SET @ResData = ''
SET @InData = ''
WHILE(LEN(@RangeValue)>1)
BEGIN
	SET @Pos = CHARINDEX(',',@RangeValue,1)
	SET @rId = SUBSTRING(@RangeValue,1,@Pos-1)	
	SET @ResData = @ResData + CASE WHEN @ResData <> '' THEN ','
ELSE '' END + 'ISNULL(['+ CAST(@rId AS VARCHAR(5)) + '],0)
AS Range' + CAST(@rId AS VARCHAR(5))
	SET @InData = @InData + CASE WHEN @InData <> '' THEN ','
ELSE '' END + '['+ CAST(@rId AS VARCHAR(5)) + ']'
	SET @RangeValue=SUBSTRING(@RangeValue,@Pos+1,LEN(@RangeValue))
END

SET @Qry = 
'SELECT '
	+ @ResData + 
' FROM 
(
	SELECT Col1 FROM table1(NoLock)
) p
PIVOT
(
	MAX (Col1) FOR Col1 IN (' + @InData + ')
) AS pvt'

--PRINT (@Qry)
EXEC (@Qry)
 
Is This Answer Correct ?    1 Yes 0 No
Jk.garg25
 
 
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
what is differece between union and union all  4
How to list all tables having unique constraints in any of the columns in a database.  1
How to Check Whether a Global Temporary Exists in a SQL Database or not?  2
Wht is the difference between stored procedure and trigger TCS4
What is difference between Triggers and store procedure?  2
MULTICAST DELEGATES IN C#.NET WITH REAL TIME EXAMPLE IBM1
difference between sql server2000 and sql server2005 KPMG1
what is physical sort data and logical sort data in index?  2
How are SQL Server databases physically stored under Windows 2000?  1
What is a Trace frag?Where can we use this?  1
What is normalization and what are the different forms of normalizations?  1
What are constraints? Explain different types of constraints?  6
What is normalization?  6
What is a view?  4
What are the advantages of using stored procedures? Please don't simply say compilation time will be saved as they are already complied. Please specify some other advantages. 247Customer3
What is a transaction and what are ACID properties? IBM4
Would it be a good idea to create an index on a table that always contains 10 records? Why or why not?  3
What is Peer to peer Replication? HCL1
table:employee EID ENAME MID(manager ids) 101 rama null 102 sita 101 103 siva 101 104 ganesh 103 . . . . . . for 103 ID the manager ID is 101(RAMA) and for 104 manager is SIVA if i give employee id (EID) you have to tell the manager for that EID write query? eample:if i give 102 .The query output should be manager for 102 ID that it should print RAMA as output  5
Explain sp_configure commands, set commands?  3
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com