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
 SQL - Loto Simplification Code - sayi[i]

Author  Topic 

eser__cakir
Starting Member

2 Posts

Posted - 2013-12-21 : 17:54:51
Hello ;

I need to simplfy that part of code which are marked with *.
How can I handle it ?

Thank you.

sayi[i] >>>>> ???

CODE;

----
-- SAYISAL LOTO PROCEDURU output veren SP ile

Create Proc Sayisal_Loto
@sayi1 int,@sayi2 int,@sayi3 int,@sayi4 int,@sayi5 int,@sayi6 int,
@tutan int output
as
begin
-- Çekilisi yap;
declare @counter int , @loto int
set @counter=1
set @loto=0
truncate table Cekilis
while (@counter <= 6)
begin
-- Çekilen sayi 0 yada öncekilerin aynisi olmamali!
while (@loto=0)
begin
set @loto= FLOOR(RAND() * 49)
if ((select COUNT(*) from Cekilis where Sayi=@loto) > 0 or @loto=0) -- Ayni sayi var mi? veya 0 mi?
begin
set @loto=0
end
end
-- Çekilen sayi 0 yada öncekilerin aynisi olmamali!
insert into dbo.Cekilis (Sayi) values (@loto)
set @counter=@counter+1
set @loto=0
end
end
-- SEÇILEN RAKAMLARI yaz
truncate table Oynanan
***************************************************
insert into Oynanan (Oynanan_Sayi) values (@sayi1)*
insert into Oynanan (Oynanan_Sayi) values (@sayi2)*
insert into Oynanan (Oynanan_Sayi) values (@sayi3)*
insert into Oynanan (Oynanan_Sayi) values (@sayi4)*
insert into Oynanan (Oynanan_Sayi) values (@sayi5)*
insert into Oynanan (Oynanan_Sayi) values (@sayi6)*
***************************************************
set @tutan=(select COUNT(*) from Cekilis cross join Oynanan where Cekilis.Sayi=Oynanan.Oynanan_Sayi)

-- Kontrol ---------------------

select * from Cekilis full join Oynanan ON Cekilis.id=Oynanan.id

--------- PROCEDURU Çalistirmak Için -------------

declare @adet int
exec Sayisal_Loto 11,12,13,14,15,16, @adet output
print @adet

------------------------------------------

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2013-12-21 : 18:00:50
[code]insert into Oynanan (Oynanan_Sayi) values (@sayi1)
,(@sayi2)
,(@sayi3)
,(@sayi4)
,(@sayi5)
,(@sayi6)[/code]
Go to Top of Page

eser__cakir
Starting Member

2 Posts

Posted - 2013-12-21 : 18:13:50
quote:
Originally posted by bitsmed

insert into Oynanan (Oynanan_Sayi) values (@sayi1)
,(@sayi2)
,(@sayi3)
,(@sayi4)
,(@sayi5)
,(@sayi6)




what if I have 1000 records

I meant ;

declare @a int
set @a=1
while (@a<1000)
begin
insert into ..............fill the blank pls........
set @a=@a+1
end
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-12-22 : 03:09:42
If you've 1000 records its probably best passing them through xml value or in delimited format. Then parse the individual values out and do the insert
see
http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm

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

- Advertisement -