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 this query not work

Author  Topic 

Ali.M.Habib
Yak Posting Veteran

54 Posts

Posted - 2009-01-28 : 06:03:01
[code]create table #DISTINCTC(
[name] nvarchar(120)
)
insert into #DISTINCTC SELECT Column_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE Table_Name = 'GLIF'
------------------------
select [name]from #DISTINCTC
declare Dist cursor for
select [name]from #DISTINCTC
open Dist
DECLARE @z nvarchar(50)
Declare @word nvarchar(200)
declare @x nvarchar(120)
declare @y nvarchar(120)
--SET @WORD =

fetch next from Dist into @x
while @@fetch_status=0
begin
set @y = @x;
--print @y
sp_executesql 'select count(distinct @y) from GLIF' , @z output

print @z
fetch next from Dist into @x
end
close Dist
Deallocate Dist
drop table #DISTINCTC

[/code] I think the error in sp_executesql
I read alot in msdn but I can't reach any result so any help please ,I'm new in sql server

AvanthaSiriwardana
Yak Posting Veteran

78 Posts

Posted - 2009-01-30 : 00:14:55
Problem with your insert statement.
insert into #DISTINCTC SELECT Column_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE Table_Name = 'GLIF'

it should be like this ;..>
insert into #DISTINCTC(name) SELECT Column_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE Table_Name = 'GLIF'


Avantha Siriwardana
Go to Top of Page
   

- Advertisement -