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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 why not work please

Author  Topic 

Ali.M.Habib
Yak Posting Veteran

54 Posts

Posted - 2009-01-28 : 04:15:23
[code]declare Dist cursor for
select [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
end
close 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_1
SOC
BRCH
FCY_CODE
GL_CLASS_CODE
DESCRIPTION
POSTING_IND
TRANS_DATE
LCY_AMT
FCY_AMT
REVERSAL_CODE
REVERSAL_DATE
GLIF_REFERENCES
SOURCE_APPLN
PS_JOURNAL_ID
PS_JOURNAL_NBR
CNTL_CENTRE
LCY_NPV_AMT
FCY_NPV_AMT
FIL01

(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 like

EXEC('select count(distinct(cast('+@y +' as nvarchar))) from GLIF')
Go to Top of Page

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 like

EXEC('select count(distinct(cast('+@y +' as nvarchar))) from GLIF')


I want to compare the output of the result
if < 10 or < 50
what shall I do please
when say if (EXEC('select count(distinct(cast('+@y +' as nvarchar))) from GLIF')
>= 10 ) give error : suntax error near exec
Go to Top of Page

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.
Go to Top of Page

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 output


but it give error , i reas msdn helpwithout any help , so could u please correct tit for me
Go to Top of Page
   

- Advertisement -