Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


WRITE A FUNCTION TO DISPLAY THE OUTPUT OF AN EXISTING TABLE
RANGE LIKE COMMAM SEPERATED VALUES LIKE RANGE1,RANGE2,...

Answers were Sorted based on User's Feedback



WRITE A FUNCTION TO DISPLAY THE OUTPUT OF AN EXISTING TABLE RANGE LIKE COMMAM SEPERATED VALUES LIK..

Answer / carmel franco

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 ?    2 Yes 0 No

WRITE A FUNCTION TO DISPLAY THE OUTPUT OF AN EXISTING TABLE RANGE LIKE COMMAM SEPERATED VALUES LIK..

Answer / jk.garg25

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

Post New Answer

More SQL Server Interview Questions

What is dimension table? : sql server analysis services, ssas

0 Answers  


It is important form e to get the information from log files of applications executed by the task scheduler? Does sql studio save these log files? : sql server management studio

0 Answers  


What is the diff between Static Queries and Dynamic queries give me some examples

2 Answers   CSC,


How to concatenate two strings in SQL Server.

0 Answers   HCL,


What the different topologies in which replication can be configured?

0 Answers  


How is sql server used?

0 Answers  


What is the difference between 2-Tier architecture and 3-Tier architecture

15 Answers   CTS, MCN Solutions, Oracle,


can any one say how to update the following senario I have a table <srabank> in which the table structure is as follows ANAME ACCNO LOCATION ACCTYPE BAL SBanuPrakash 31518746291 Punganur deposit 4000 Sreenivas 31518746292 mahoobnagar current 14000 Ranjith 31518746293 Karimnagar Savings 2000 Giresh 31518746294 Chennai deposit 40000 Boo 31518746295 Chennai Savings 20000 Jay 31518746296 Valachari Savings 1000 tirumalraj 31518746297 Vellore Savings 8000 The senario is We need to select one account number and check the balance after checking the balance if the balance exist we need to transfer to another account . in the from account the amount need to be reduced and in the to account the amount needed to be added. for example for the <accountno> <31518746291> the balance is <4000> for the <accno> <31518746292> the balance is <14000> after transferring the balance the details will look as follows <accno><31518746291> <bal> <2000> <accno><31518746292> <bal> <16000> the above mentioned two statment will come under the final result.

3 Answers  


what is difference between Enterprise Manager and Query Analyer

6 Answers   CTS,


Define Unique Key?

0 Answers   HCL,


How can you get @@error and @@rowcount at the same time?

9 Answers  


Does hive support indexing?

0 Answers  


Categories