4000 is the max length for nvarchar. Should be:
"Imran Koradia" <nojunk@microsoft.com> wrote in message
news:eqt4MyGXEHA.3120@TK2MSFTNGP12.phx.gbl...
> thats what sql server expects the type of @sql. declare ur @sql variable
as:
> DECLARE @sql as nvarchar(8000)
>
> check out
http://www.sommarskog.se/dynamic_sql.html for more info.
>
> hope this helps..
>
> "rob" <rwc1960@bellsouth.net> wrote in message
> news:f4DDc.1087$JP6.996@bignews3.bellsouth.net...
> > Hi Roji,
> >
> > Changed it to the following in order to store the results to a
variable...
> >
> > DECLARE @sql as varchar(8000)
> > DECLARE @SalespersonDB as varchar(8000)
> > DECLARE @cnt as nvarchar(10)
> >
> > set @SalespersonDB = 'EJ'
> >
> > set @sql = 'Select @cnt = cast(Count(*) as nvarchar(10)) FROM ' +
> > @SalespersonDB + '.dbo.sysobjects WHERE (xtype = ''U'') and name =
> > ''tblCustPrClChanlSlsREP'''
> > print @sql
> > Exec sp_executesql @sql, N'@cnt nvarchar(10) OUTPUT', @cnt OUTPUT
> > print @cnt
> >
> > Resulted in ERROR....
> > Server: Msg 214, Level 16, State 2, Procedure sp_executesql, Line 10
> > Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
> >
> >
> >
> > "Roji. P. Thomas" <lazydragon@nowhere.com> wrote in message
> > news:uT%23stPFXEHA.3632@TK2MSFTNGP10.phx.gbl...
> > > Oh Rob,
> > >
> > > You are trying to mix dynamic SQL and Static SQL.
> > > You cannot do that. Your Else condition doesnt have a
> > > corresponding IF condition. thats why you are getting the error.
> > >
> > > To learn more abt dynamic SQL read
> > >
> > >
http://www.sommarskog.se/dynamic_sql.html > > >
> > >
> > > --
> > > Roji. P. Thomas
> > > SQL Server Programmer
> > > "rob" <rwc1960@bellsouth.net> wrote in message
> > > news:PKzDc.129$O3.27@bignews2.bellsouth.net...
> > > > I am doing something wrong in the code below...
> > > >
> > > > This section fails within the cursor... I am attempting to check for
> > > > existence of a table in the database names I am looping through...
> > > >
> > > > As is, Error is Incorrect syntax near keyword 'ELSE'
> > > > If I comment out from BEGIN to the END, Error is Incorrect syntax
> near
> > > ')'
> > > >
> > > > Thanks !
> > > >
> > > > DECLARE @sql as varchar(8000)
> > > > DECLARE @SalespersonDB as varchar(8000)
> > > >
> > > > set @SalespersonDB = 'EJ'
> > > > set @sql = ' if exists (select * from dbo.sysobjects where id =
> > > object_id(['
> > > > + @SalespersonDB + '].[dbo].[tblCustPrClChanlSlsREP]))'
> > > > print @sql
> > > > Exec(@sql)
> > > > BEGIN
> > > > Print 'Do nothing'
> > > > END
> > > > ELSE
> > > > BEGIN
> > > > Print 'Do something'
> > > > End
> > > >
> > > >
> > >
> > >
> >
> >
>
>