PDA

View Full Version : اشکال در ساخت کرزر



mahnaz_h
پنج شنبه 14 شهریور 1387, 16:11 عصر
نمی دونم چرا این کرزر پیغام خطا می ده؟!

declare @Id int
create ShopCursor cursor
for select Id from TShop
open ShopCursor
fetch ShopCursor into @Id
while (@@sqlstatus = 0)
begin
fetch ShopCursor into @Id
select @Id
end
close ShopCursor
deallocate cursor ShopCursor
select @Id

پیغام خطاش هم:

Server: Msg 170, Level 15, State 1, Line 20
Line 20: Incorrect syntax near 'ShopCursor'.
Server: Msg 137, Level 15, State 1, Line 24
Must declare the variable '@@sqlstatus'.
Server: Msg 156, Level 15, State 1, Line 30
Incorrect syntax near the keyword 'cursor'.

دستوراتش را عینا از کتاب نوشتم . چرا این پیغام ها رو میده؟
جدولی با نام ُTShopهم موجود و ساخته شده است و حاوی تعدادی رکورد است

AminSobati
پنج شنبه 14 شهریور 1387, 17:58 عصر
به جای create از declare استفاده کنید. متغیر sqlstatus رو تعریف نکردین. موقع deallocate دیگه cursor لازم نیست بنویسین

mahnaz_h
پنج شنبه 14 شهریور 1387, 20:58 عصر
ممنون . ولی sqlstatus رو از چه نوعی باید تعریف کنم؟ تو کتاب نوشته بود به عنوان یک چک کننده آخر رکورد به کار می رود و تعریف نکرده بود.
فکر کردم خودش مثل تابع تعریف شده است

AminSobati
پنج شنبه 14 شهریور 1387, 22:23 عصر
ضرر نداره، int بگیرین

mahnaz_h
جمعه 15 شهریور 1387, 11:37 صبح
declare @Nname varchar (20)
declare @Family varchar (30)
declare @Tel varchar (13)
declare @Address varchar (100)
declare @SarGhofli bit
declare @Malekiat bit
declare @Mogheiat varchar (6)
declare @Emtiazat varchar (4)
declare @NoeMoamele varchar(1)
declare @Pardakht1 float
declare @Pardakht2 float
declare @Metraj int
declare @BalkonChandMetr int
declare @Tozihat varchar (200)
declare @Id int
declare @@sqlstatus int
begin
insert into TShop (Nname,Family,Tel, Address,sarGhofli,Malekiat,Mogheiat,Emtiazat,NoeMo amele,Pardakht1,Pardakht2,Metraj,BalkonChandMetr,T ozihat)
values ('fghf','juj','52785','yujuy',0, 1 ,'bar1', '12', 'f',525,52,44, 0 , 'gdhnjgj')
declare ShopCursor cursor
for select Id from TShop
open ShopCursor
fetch ShopCursor into @Id
while (@@sqlstatus = 0)
begin
fetch ShopCursor into @Id
select @Id
end
close ShopCursor
deallocate ShopCursor




حالا این پیغام رومیده:
Server: Msg 170, Level 15, State 1, Line 36
Line 36: Incorrect syntax near 'ShopCursor'.