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 |
Ali.M.Habib
Yak Posting Veteran
54 Posts |
Posted - 2009-01-28 : 04:15:23
|
[code]declare Dist cursor forselect [name]from #DISTINCTC open Dist DECLARE @z nvarchar(500) --Declare @word nvarchar(200) declare @x nvarchar(120) declare @y nvarchar(120) fetch next from Dist into @x while @@fetch_status=0 begin set @y = @x; print @y select count(distinct(cast(@y as nvarchar))) from GLIF fetch next from Dist into @x endclose Dist Deallocate Dist drop table #DISTINCTC[/code]the out put of the select is just 1 for all column@y not return value in the select how canI solve the the result is name ------------------------------------------------------------------------------------------------------------------------ KEY_1SOCBRCHFCY_CODEGL_CLASS_CODEDESCRIPTIONPOSTING_INDTRANS_DATELCY_AMTFCY_AMTREVERSAL_CODEREVERSAL_DATEGLIF_REFERENCESSOURCE_APPLNPS_JOURNAL_IDPS_JOURNAL_NBRCNTL_CENTRELCY_NPV_AMTFCY_NPV_AMTFIL01(20 row(s) affected)KEY_1 ----------- 1(1 row(s) affected)SOC ----------- 1(1 row(s) affected)BRCH ----------- 1(1 row(s) affected)FCY_CODE ----------- 1(1 row(s) affected)GL_CLASS_CODE ----------- 1(1 row(s) affected)DESCRIPTION ----------- 1(1 row(s) affected)POSTING_IND ----------- 1(1 row(s) affected)TRANS_DATE ----------- 1(1 row(s) affected)LCY_AMT ----------- 1(1 row(s) affected)FCY_AMT ----------- 1(1 row(s) affected)REVERSAL_CODE ----------- 1(1 row(s) affected)REVERSAL_DATE ----------- 1(1 row(s) affected)GLIF_REFERENCES ----------- 1(1 row(s) affected)SOURCE_APPLN ----------- 1(1 row(s) affected)PS_JOURNAL_ID ----------- 1(1 row(s) affected)PS_JOURNAL_NBR ----------- 1(1 row(s) affected)CNTL_CENTRE ----------- 1(1 row(s) affected)LCY_NPV_AMT ----------- 1(1 row(s) affected)FCY_NPV_AMT ----------- 1(1 row(s) affected)FIL01 ----------- 1(1 row(s) affected) |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-28 : 04:25:40
|
you cant pass the column name like this. for this you need dynamic sql. something likeEXEC('select count(distinct(cast('+@y +' as nvarchar))) from GLIF') |
|
|
Ali.M.Habib
Yak Posting Veteran
54 Posts |
Posted - 2009-01-28 : 04:35:38
|
quote: Originally posted by visakh16 you cant pass the column name like this. for this you need dynamic sql. something likeEXEC('select count(distinct(cast('+@y +' as nvarchar))) from GLIF')
I want to compare the output of the resultif < 10 or < 50 what shall I do pleasewhen say if (EXEC('select count(distinct(cast('+@y +' as nvarchar))) from GLIF') >= 10 ) give error : suntax error near exec |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-01-28 : 04:44:44
|
for that you need to declare an output variable and use sp_executesql to get it value and use it for comparison. |
|
|
Ali.M.Habib
Yak Posting Veteran
54 Posts |
Posted - 2009-01-28 : 05:02:03
|
quote: Originally posted by visakh16 for that you need to declare an output variable and use sp_executesql to get it value and use it for comparison.
sorry but i tried that code SET @WORD = 'select count(distinct @y ) from GLIF'exec sp_executesql @word,@y, @z outputbut it give error , i reas msdn helpwithout any help , so could u please correct tit for me |
|
|
|
|
|