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
 General SQL Server Forums
 New to SQL Server Programming
 error declare select

Author  Topic 

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2013-07-15 : 02:05:44


create table kateqor
(id int not null identity(1,1),
Name nvarchar(50))

insert into kateqor
(Name)
values
(N'M?nzild? qurum')

select*from kateqor



but when I do a query

declare @kat nvarchar(50)
set @kat='M?nzild? qurum'
select * from kateqor where Name=N(@kat)


I receive an error

Post 195, Level 15, state 10, line 4
'N' is not a recognized function name.

kmkmmm

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-15 : 02:12:50
it should be


declare @kat nvarchar(50)
set @kat=N'M?nzild? qurum'
select * from kateqor where Name=@kat


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2013-07-15 : 02:23:36
thank you visakh

create procedure insert11
@kat nvarchar(50)
as
select * from kateqor where Name=@kat

exec insert11 N'M?nzild? qurum'

but the problem is that I need to send only @kat
without N '


how mak i create proc

execute only @kat

for example

exec insert111 'M?nzild? qurum'


without N'


kmkmmm
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-15 : 02:33:31
quote:
Originally posted by pascal_jimi

thank you visakh

create procedure insert11
@kat nvarchar(50)
as
select * from kateqor where Name=@kat

exec insert11 N'M?nzild? qurum'

but the problem is that I need to send only @kat
without N '


how mak i create proc

execute only @kat

for example

exec insert111 'M?nzild? qurum'


without N'


kmkmmm


if you need to send value as unicode then you should use N as prefix otherwise it'll interpret it as normal varchar string.

exec insert111 N'M?nzild? qurum'

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -