Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-09-17 : 08:27:56
|
| Hemant writes "The table design we have is such that we fire one query to get the name of the column that we have to select in the other query. I have done this by first getting the column name from the first query:Declare @Column nvarchar(20)SELECT @Column=ColumnName FROM tableThis variable @Column is used to build another query which is executed using EXEC(@Query)DECLARE @Query nvarchar(1024)SELECT @Query = 'SELECT ' + @Column + ' FROM something'EXEC(@Query)Now, I have a generic function which takes in the above query and returns the dataset when executed directly and the count of the records when appended withSELECT COUNT(*) FROM (// Query Appended HERE //) ALIASThe dataset is obtained successfully but the problem lies in getting the recordcount using the same query.Looking for a help on the same.Thanks!" |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-09-18 : 06:43:43
|
| [code]USE NorthwindGOSET NOCOUNT ONCREATE TABLE #MyTempTable( MyRowCount int)INSERT INTO #MyTempTable (MyRowCOunt)EXEC ('SELECT COUNT(*) FROM (SELECT * FROM dbo.Customers) X')SELECT * FROM #MyTempTableSELECT COUNT(*) AS [CustomerCount] FROM dbo.CustomersDROP TABLE #MyTempTableSET NOCOUNT OFF[/code]Kristen |
 |
|
|
|
|
|