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.
Author |
Topic |
oguzkaygun
Yak Posting Veteran
53 Posts |
Posted - 2009-02-24 : 07:20:20
|
hi i have UserId(coulumname) in amagazalar (name of table) and i have UserId(coulumname) in urunlistesi (name of table)... UserId in magazalar can be only one name.. for example john, smith etc.. (there is no john,john in Userid.. there is only one John in Userid) but UserId in urunlistesi can be more than one name like john, john, john, smith, smith, smith..But when UserId in urunlistesi can be more than one, there is error message that "Limitations cant be enable.. One row or more row is not Null..One row or more row have unsame, foreign key limitations..."For example, my scenirio of tables is belowuserid in magazalar (coulumname, table name) userid in urunlistesi (coulumname, table name)John JohnSmith JohnBeckham John Smith Smith Bechkam Beckham Result only should be John and information of John(1 record) where there is John in urunlistesi....(where kategory=@kategory1 and kategory2=@kategory2) (There are a lot of records about John but Result should be only 1 record.. John and information of John)But when there is two John in urunlistesi, there is error message that i wrote above.. if there is one John in urunlistesi, i can see record in gridview1.. How can it work with a lot of John in urunlistesi ? How can i enter a lot of john or smith (UserId) for urunlistesi ? how can i run it ?hii have tried for FULL JOIN and JOIN. i didnt use Grop By or Distinct.. but i saw same error message. because there is two john(coulumname) in urunlistesi (table). what should i do ?Note: when i change my class.vb or my dataset.xsd, i wait 15 or more minute for build. So i cant reply soon. Sorry.What i need exactly ? i have two tables (amagazalar(UserId, Information as coulumname) and urunlistesi(UserId, category, categorychild, childchildcategory as coulumname))for example there is one record in amazalar(table) that UserId is John. and there are alot of records in urunlistesi(table) that Userid are John. i have three categories.. category, childcategory, childchildcategory in urunlistesi(table)..so when i click category or childcategory or childchildcategory, there are records that userid are John in urunlistesi.. but i should see only John and information of John in amagazalar at gridview1 if there are John in urunlistesi..when i click cagetory, maybe there are 5 John in urunlistesi. but i should see only one John and information of John from amagazalarelse example.. when i click categorychild, there are 3 John and there are 5 Smith in urunlistesi(table).. but i should see 1 John and information of John and i should see 1 Smith and information of Smith from amagazalar(table)..How can i do it ?My join is below...Note : UserId dont have primary or else key at tableINNER JOIN urunlistesi as B on A.UserId = B.UserId Thanksmy stored procedure is below.. when i write outer instead of inner, i cant save it.. what should i do ?ALTER PROCEDURE dbo.magazalarliste @kategori varchar(23), @kategori1 varchar(48), @kategori2 varchar(55), @StartRowIndex INT, @NumRows INT/*@aktifmagaza varchar(5),@ilanturu varchar(18),@aktifilan varchar(5),A.aktifmagaza = @aktifmagaza and B.ilanturu = @ilanturuand B.aktifilan = @aktifilanandSET NOCOUNT ONSET Statistics io ON */ASBEGIN ;WITH ListEntries AS ( SELECT ROW_NUMBER() OVER (ORDER BY amagazalar.[onsira], amagazalar.[magazanumarasi] desc) AS Row, amagazalar.magazanumarasi, amagazalar.UserId, amagazalar.madi, amagazalar.maciklama, amagazalar.resim1, amagazalar.urunsayisi, amagazalar.onsira, amagazalar.aktifmagaza, urunlistesi.ilanturu, urunlistesi.aktifilan, urunlistesi.kategori, urunlistesi.kategori1, urunlistesi.kategori2FROM amagazalar outer JOIN urunlistesi on amagazalar.UserId = urunlistesi.UserIdwhere urunlistesi.kategori = @kategori and ((@kategori1 is null) or (urunlistesi.kategori1 = @kategori1))and ((@kategori2 is null) or (urunlistesi.kategori2 = @kategori2))group by amagazalar.magazanumarasi, amagazalar.UserId, amagazalar.madi, amagazalar.maciklama, amagazalar.resim1, amagazalar.urunsayisi, amagazalar.onsira, amagazalar.aktifmagaza, urunlistesi.ilanturu, urunlistesi.aktifilan, urunlistesi.kategori, urunlistesi.kategori1, urunlistesi.kategori2 ) SELECT *FROM ListEntries WHERE Row between @StartRowIndex and @StartRowIndex+@NumRowsEND RETURN |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
|
oguzkaygun
Yak Posting Veteran
53 Posts |
Posted - 2009-03-02 : 06:35:23
|
hi i have two tables (amagazalar(UserId, Information as coulumname) and urunlistesi(UserId, category, categorychild, childchildcategory as coulumname))amagazalar (table)UserId Information1 jfdkjfd2 dkfdf3 jfdkjdjurunlistesi (table)UserId kategori kategori1 kategori21 computer hardisk 80 Gb1 computer hardisk 160 Gb2 phone Samsung ...........2 phone Nokia ..........i want to joing UserId=UserIdfor example there is one record in amazalar(table) that UserId is John. and there are alot of records in urunlistesi(table) that Userid are John. i have three categories.. category, childcategory, childchildcategory in urunlistesi(table)..so when i click category or childcategory or childchildcategory, there are records that userid are John in urunlistesi.. but i should see only John and information of John from amagazalar at gridview1 if there are John in urunlistesi..when i click cagetory, maybe there are 5 John in urunlistesi. but i should see only one John and information of John from amagazalarelse example.. when i click categorychild, there are 3 John and there are 5 Smith in urunlistesi(table).. but i should see 1 John and information of John and i should see 1 Smith and information of Smith from amagazalar(table)..How can i do it ?i wrote below Storedprocedure but it works wrongly.. Storedprocedure should be work for 1.000.000 records in urunlistesi and 100.000 records in amagazalarALTER PROCEDURE dbo.magazalarliste @aktifmagaza varchar(5),@ilanturu varchar(18), @aktifilan varchar(5),@kategori varchar(23), @kategori1 varchar(48), @kategori2 varchar(55), @StartRowIndex INT, @NumRows INTASbegin;with Listurunlistesi as (SELECT ROW_NUMBER() OVER (order by UserId asc) AS Row, UserIdFROM urunlistesiwhere ilanturu = @ilanturuand aktifilan = @aktifilanand kategori = @kategori and ((@kategori1 is null) or (kategori1 = @kategori1))and ((@kategori2 is null) or (kategori2 = @kategori2))group by UserId ) SELECT ROW_NUMBER() OVER (ORDER BY amagazalar.[onsira], amagazalar.[magazanumarasi] desc) AS Roww, amagazalar.magazanumarasi, amagazalar.UserId, amagazalar.madi, amagazalar.maciklama, amagazalar.resim1, amagazalar.urunsayisi, amagazalar.[onsira]FROM amagazalar inner join Listurunlistesi on Listurunlistesi.UserId = amagazalar.UserId WHERE aktifmagaza = @aktifmagazaand Row between @StartRowIndex and @StartRowIndex+@NumRowsendRETURN My second storedprocedure is below..But when UserId in urunlistesi can be more than one in urunlistesi (table), there is error message that "Limitations cant be enable.. One row or more row is not Null..One row or more row have unsame, foreign key limitations..."ALTER PROCEDURE dbo.magazalarliste @kategori varchar(23), @kategori1 varchar(48), @kategori2 varchar(55), @StartRowIndex INT, @NumRows INT/*@aktifmagaza varchar(5),@ilanturu varchar(18),@aktifilan varchar(5),A.aktifmagaza = @aktifmagaza and B.ilanturu = @ilanturuand B.aktifilan = @aktifilanandSET NOCOUNT ONSET Statistics io ON */ASBEGIN ;WITH ListEntries AS ( SELECT ROW_NUMBER() OVER (ORDER BY amagazalar.[onsira], amagazalar.[magazanumarasi] desc) AS Row, amagazalar.magazanumarasi, amagazalar.UserId, amagazalar.madi, amagazalar.maciklama, amagazalar.resim1, amagazalar.urunsayisi, amagazalar.onsira, amagazalar.aktifmagaza, urunlistesi.ilanturu, urunlistesi.aktifilan, urunlistesi.kategori, urunlistesi.kategori1, urunlistesi.kategori2FROM amagazalar outer JOIN urunlistesi on amagazalar.UserId = urunlistesi.UserIdwhere urunlistesi.kategori = @kategori and ((@kategori1 is null) or (urunlistesi.kategori1 = @kategori1))and ((@kategori2 is null) or (urunlistesi.kategori2 = @kategori2))group by amagazalar.magazanumarasi, amagazalar.UserId, amagazalar.madi, amagazalar.maciklama, amagazalar.resim1, amagazalar.urunsayisi, amagazalar.onsira, amagazalar.aktifmagaza, urunlistesi.ilanturu, urunlistesi.aktifilan, urunlistesi.kategori, urunlistesi.kategori1, urunlistesi.kategori2 ) SELECT *FROM ListEntries WHERE Row between @StartRowIndex and @StartRowIndex+@NumRowsEND |
|
|
|
|
|
|
|