PDA

View Full Version : حرفه ای: نمایش تکراری رکورد SQL با وجود distinct



teymoorei
دوشنبه 07 آذر 1401, 17:10 عصر
سلام

مشکل کد زیر کجاست که تکراری نمایش میده ؟

Dim da As New SqlDataAdapter("SELECT distinct tblcustomer.name,tblconsignment.idl,tblconsignment .weight,tblconsignment.indate,tblOutConsignment.Id o,tblOutConsignment.idc,tblOutConsignment.idl,tblO utConsignment.kharid_carton,tblOutConsignment.cart on_number,tblOutConsignment.carton_price,tblOutCon signment.carton_total,tblOutConsignment.kharid_rog han,tblOutConsignment.roghan_number,tblOutConsignm ent.roghan_price,tblOutConsignment.roghan_total,tb lOutConsignment.kharid_plastic,tblOutConsignment.p lastic_number,tblOutConsignment.plastic_price,tblO utConsignment.plastic_total,tblOutConsignment.khar id_shring,tblOutConsignment.shring_number,tblOutCo nsignment.shring_price,tblOutConsignment.shring_to tal,tblOutConsignment.package_tape,tblOutConsignme nt.grade1,tblOutConsignment.grade2,tblOutConsignme nt.grade3,tblOutConsignment.sort_price_package,tbl OutConsignment.other_price,tblOutConsignment.sort_ price,tblOutConsignment.out_date,tblOutConsignment .gale,tblOutConsignment.discount,tblOutConsignment .all_total,tblOutConsignment.disc,tblOutConsignmen t.sal_mali,tblOutConsignment.darsad_drop,tblOutCon signment.weight_pure,tblOutConsignment.weight_drop ,tblOutConsignment.deposit,tblOutConsignment.remai ns,tblOutConsignment.clearing FROM tblcustomer,tblconsignment,tblOutConsignment WHERE tblcustomer.idc=tblOutConsignment.idc AND tblcustomer.idc IN(SELECT distinct tblOutConsignment.idc FROM tblOutConsignment WHERE tblconsignment.idl=tblOutConsignment.idl)", con)

teymoorei
دوشنبه 07 آذر 1401, 17:52 عصر
رکورد های من رو تکراری نمایش میده درحالی که یک با ثبت شده

مثلا "علی" یک رکورد داره اما دوبار نمایش میده

ROSTAM2
دوشنبه 07 آذر 1401, 22:38 عصر
رکورد های من رو تکراری نمایش میده درحالی که یک با ثبت شده

مثلا "علی" یک رکورد داره اما دوبار نمایش میده

از کجا معلوم شاید دوبار ثبت می شه!

teymoorei
دوشنبه 07 آذر 1401, 23:37 عصر
چون میرم توی sqlexpress و میبینم که یک رکورده فقط

teymoorei
سه شنبه 08 آذر 1401, 11:28 صبح
دوستان ممنون میشم راهنمایی بفرمایید خیلی گیرم

سه تا جدوله (مشخصات مشتری ، بار های مشتری ، بار خرووجی)

مشتری اگه دو تا بار خروجی داشته باشه همونارو چهار بار نشون میده

ROSTAM2
سه شنبه 08 آذر 1401, 20:05 عصر
سلام.
بنظر خودت الآن ما باید از رو چه چیزی بفهمیم مشکل برنامه ات چیه؟ :متفکر:

teymoorei
سه شنبه 08 آذر 1401, 21:55 عصر
سلام
کلی خندیدم شاید حق با شماست :قهقهه::قهقهه::قهقهه::قهقهه:

اما از روی اینکه توضیح دادم خدمتتون :

من یه جدول دارم به نام (مشخصات مشتری) یه جدول به نام (بار های مشتری) ، یه جدول هم به نام (بار های خروجی) .

id مشتری (idc) ، id بار (idl) و id بارخروجی (idl) هست .

حالا توی دستور گفتم انتخاب کن مشتری هایی که یه بار دارند و اون بار توی جدول خروجی ثبت شدن رو نمایش بده .

دستور بالا هم سه بخش داره :

1- انتخاب (Select )فیلد های مورد نظر از سه جدول مشتری (tblcustomer) ، جدول بار (tblconsigment) و جدول خروج بار مشتری (tbloutconsigment) :

SELECT tblcustomer.name,tblconsignment.idl,tblconsignment .weight,tblconsignment.indate,tblOutConsignment.Id o,tblOutConsignment.idc,tblOutConsignment.idl,tblO utConsignment.kharid_cartonFR
OM tblcustomer,tblconsignment,tblOutConsignment2- درصورتی که id مشتری در جدول خروج بار ثبت شده یعنی id مشتری توی جدول خروج بار وجود داشت :
WHERE tblcustomer.idc=tblOutConsignment.idc3- و درصورتی که بار مشتری توی بار خروجی ثبت شده بود :
AND tblcustomer.idc IN(SELECT tblOutConsignment.idc FROM tblOutConsignment WHERE tblconsignment.idl=tblOutConsignment.idl)

حالا مساله اینجاست که خروجی درست میده ولی اگه یه مشتری دو تا بار داشت (مثلا برای مشتری علی دو تا فاکتور (بار) ثبت شده بود) چهار بار نمایش میده ، همون دو تا بار رو دوباره هم نمایش میده

ببخشید که طولانی شد ، سعی کردم تا حد امکان توضیحاتم کامل و قابل درک باشه .

ROSTAM2
سه شنبه 08 آذر 1401, 22:22 عصر
مگه دیتا گریدویو برای هر جدول مجزا نیست؟!

teymoorei
سه شنبه 08 آذر 1401, 22:26 عصر
نه خروجی دستور زیر توی یه دیتاگریده :

Dim da As New SqlDataAdapter("SELECT distinct tblcustomer.name,tblconsignment.idl,tblconsignment .weight,tblconsignment.indate,tblOutConsignment.Id o,tblOutConsignment.idc,tblOutConsignment.idl,tblO utConsignment.kharid_carton,tblOutConsignment.cart on_number,tblOutConsignment.carton_price,tblOutCon signment.carton_total,tblOutConsignment.kharid_rog han,tblOutConsignment.roghan_number,tblOutConsignm ent.roghan_price,tblOutConsignment.roghan_total,tb lOutConsignment.kharid_plastic,tblOutConsignment.p lastic_number,tblOutConsignment.plastic_price,tblO utConsignment.plastic_total,tblOutConsignment.khar id_shring,tblOutConsignment.shring_number,tblOutCo nsignment.shring_price,tblOutConsignment.shring_to tal,tblOutConsignment.package_tape,tblOutConsignme nt.grade1,tblOutConsignment.grade2,tblOutConsignme nt.grade3,tblOutConsignment.sort_price_package,tbl OutConsignment.other_price,tblOutConsignment.sort_ price,tblOutConsignment.out_date,tblOutConsignment .gale,tblOutConsignment.discount,tblOutConsignment .all_total,tblOutConsignment.disc,tblOutConsignmen t.sal_mali,tblOutConsignment.darsad_drop,tblOutCon signment.weight_pure,tblOutConsignment.weight_drop ,tblOutConsignment.deposit,tblOutConsignment.remai ns,tblOutConsignment.clearing FROM tblcustomer,tblconsignment,tblOutConsignment WHERE tblcustomer.idc=tblOutConsignment.idc AND tblcustomer.idc IN(SELECT distinct tblOutConsignment.idc FROM tblOutConsignment WHERE tblconsignment.idl=tblOutConsignment.idl)", con)

ROSTAM2
سه شنبه 08 آذر 1401, 22:44 عصر
پس مشکل از دستور SELECTِ

بهتره با Query Builder دستورت رو چک کنی.

teymoorei
چهارشنبه 09 آذر 1401, 19:19 عصر
ممنونم مشکل حل شد