-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyEshopping2 Full Query.sql
621 lines (509 loc) · 18.1 KB
/
MyEshopping2 Full Query.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
-- cerate all table here
--1
CREATE TABLE tblBrands(
[BrandID] [int] IDENTITY(1,1) NOT NULL primary key,
[Name] [nvarchar](500) NULL,
)
--2
CREATE TABLE tblCart(
[CartID] [int] IDENTITY(1,1) NOT NULL,
[UID] [int] NULL,
[PID] [int] NULL,
[PName] [nvarchar](max) NULL,
[PPrice] [money] NULL,
[PSelPrice] [money] NULL,
[SubPAmount] AS ([PPrice]*[Qty]),
[SubSAmount] AS ([PSelPrice]*[Qty]),
[Qty] [int] NULL,
)
--3
CREATE TABLE tblCategory(
[CatID] [int] IDENTITY(1,1) NOT NULL primary key,
[CatName] [nvarchar](max) NULL,
)
---4
CREATE TABLE tblSubCategory(
[SubCatID] [int] IDENTITY(1,1) NOT NULL primary key,
[SubCatName] [nvarchar](max) NULL,
[MainCatID] [int] NULL,
CONSTRAINT [FK_tblSubCategory_tblCategory] FOREIGN KEY([MainCatID]) REFERENCES tblCategory ([CatID])
)
---------5
create table tblUsers
(
Uid int identity(1,1) primary key not null,
Username nvarchar(100)Null,
Password nvarchar(100)Null,
Email nvarchar(100)Null,
Name nvarchar(100)Null,
Usertype nvarchar(50) default 'User'
)
insert into tblUsers Values('coderbaba','123','coderbaba@yahoo.com','Coder baba','Admin')
insert into tblUsers Values('user','123','user@yahoo.com','Userbabu','User')
select * from tblUsers
---------6
CREATE TABLE tblOrderProducts(
[OrderProID] [int] IDENTITY(1,1) NOT NULL primary key,
[OrderID] [nvarchar](50) NULL,
[UserID] [int] NULL,
[PID] [int] NULL,
[Products] [nvarchar](max) NULL,
[Quantity] [int] NULL,
[OrderDate] [datetime] NULL,
[Status] [nvarchar](100) NULL,
Constraint [FK_tblOrderProducts_ToTable] FOREIGN KEY ([UserID]) REFERENCES [tblUsers] ([uid])
)
---7
create table ForgotPass
(
Id nvarchar (500) not null,
Uid int null,
RequestDateTime DATETIME null,
Constraint [FK_ForgotPass_tblUsers] FOREIGN KEY ([Uid]) REFERENCES [tblUsers] ([Uid])
)
---8
create table tblGender
(
GenderID int identity(1,1) primary key,
GenderName nvarchar(MAX)
)
--9
CREATE TABLE tblOrders(
[OrderID] [int] IDENTITY(1,1) NOT NULL primary key,
[UserID] [int] NULL,
[EMail] [nvarchar](max) NULL,
[CartAmount] [money] NULL,
[CartDiscount] [money] NULL,
[TotalPaid] [money] NULL,
[PaymentType] [nvarchar](50) NULL,
[PaymentStatus] [nvarchar](50) NULL,
[DateOfPurchase] [datetime] NULL,
[Name] [nvarchar](200) NULL,
[Address] [nvarchar](max) NULL,
[MobileNumber] [nvarchar](50) NULL,
[OrderStatus] [nvarchar](50) NULL,
[OrderNumber] [nvarchar](50) NULL,
Constraint [FK_tblOrders_ToTable] FOREIGN KEY ([UserID]) REFERENCES [tblUsers] ([uid])
)
--10
--CREATE TABLE tblProducts(
-- [PID] [int] IDENTITY(1,1) NOT NULL primary key,
-- [PName] [nvarchar](max) NULL,
-- [PPrice] [money] NULL,
-- [PSelPrice] [money] NULL,
-- [PBrandID] [int] NULL,
-- [PCategoryID] [int] NULL,
-- [PSubCatID] [int] NULL,
-- [PDescription] [nvarchar](max) NULL,
-- [FreeDelivery] [int] NULL,
-- [7DayRTN] [int] NULL,
-- [COD] [int] NULL
--)
select * from tblProducts
create table tblProducts
(
PID int identity(1,1) primary key ,
PName nvarchar(MAX),
PPrice money,
PSelPrice money,
PBrandID int,
PCategoryID int,
PSubCatID int,
PGender int,
PDescription nvarchar(MAX),
PProductDetails nvarchar(MAX),
PMaterialCare nvarchar(MAX),
FreeDelivery int,
[30DayRet] int,
COD int,
Constraint [FK_tblProducts_ToTable] FOREIGN KEY ([PBrandID]) REFERENCES [tblBrands] ([BrandID]),
Constraint [FK_tblProducts_ToTable1] FOREIGN KEY ([PCategoryID]) REFERENCES [tblCategory] ([CatID]),
Constraint [FK_tblProducts_ToTable2] FOREIGN KEY ([PSubCatID]) REFERENCES [tblSubCategory] ([SubCatID]),
Constraint [FK_tblProducts_ToTable3] FOREIGN KEY ([PGender]) REFERENCES [tblGender] ([GenderID])
)
---11
select * from tblProductImages
CREATE TABLE tblProductImages(
[PIMGID] [int] IDENTITY(1,1) NOT NULL,
[PID] [int] NULL,
[Name] [nvarchar](max) NULL,
[Extention] [nvarchar](500) NULL,
Constraint [FK_tblProductImages_ToTable] FOREIGN KEY ([PID]) REFERENCES [tblProducts] ([PID])
)
---12
create table tblSizes
(
SizeID int identity(1,1) primary key,
SizeName nvarchar(500),
BrandID int,
CategoryID int,
SubCategoryID int,
GenderID int,
Constraint [FK_tblSizes_ToBrand] FOREIGN KEY ([BrandID]) REFERENCES [tblBrands] ([BrandID]),
Constraint [FK_tblSizes_ToCat] FOREIGN KEY ([CategoryID]) REFERENCES [tblCategory] ([CatID]),
Constraint [FK_tblSizes_SubCat] FOREIGN KEY ([SubCategoryID]) REFERENCES [tblSubCategory] ([SubCatID]),
Constraint [FK_tblSizes_Gender] FOREIGN KEY ([GenderID]) REFERENCES [tblGender] ([GenderID])
)
---13
create table tblProductSizeQuantity
(
PrdSizeQuantID int identity(1,1) primary key,
PID int,
SizeID int,
Quantity int,
Constraint [FK_tblProductSizeQuantity_ToTable] FOREIGN KEY ([PID]) REFERENCES [tblProducts] ([PID]),
Constraint [FK_tblProductSizeQuantity_ToTable1] FOREIGN KEY ([SizeID]) REFERENCES [tblSizes] ([SizeID])
)
-----14
create table tblPurchase
(
PurchaseID int identity(1,1) primary key,
UserID int,
PIDSizeID nvarchar(MAX),
CartAmount money,
CartDiscount money,
TotalPayed money,
PaymentType nvarchar(50),
PaymentStatus nvarchar(50),
DateOfPurchase datetime,
Name nvarchar(200),
Address nvarchar(MAX),
PinCode nvarchar(10),
MobileNumber nvarchar(50),
CONSTRAINT [FK_tblPurchase_ToUser] FOREIGN KEY ([UserID]) REFERENCES [tblUsers]([UID])
)
-------------------------- stored procedure ----------------
---1
Create procedure sp_InsertProduct
(
@PName nvarchar(MAX),
@PPrice money,
@PSelPrice money,
@PBrandID int,
@PCategoryID int,
@PSubCatID int,
@PGender int,
@PDescription nvarchar(MAX),
@PProductDetails nvarchar(MAX),
@PMaterialCare nvarchar(MAX),
@FreeDelivery int,
@30DayRet int,
@COD int
)
AS
insert into tblProducts values(@PName,@PPrice,@PSelPrice,@PBrandID,@PCategoryID,
@PSubCatID,@PGender,@PDescription,@PProductDetails,@PMaterialCare,@FreeDelivery,
@30DayRet,@COD)
select SCOPE_IDENTITY()
Return 0
---2
create procedure procBindAllProducts
AS
select A.*,B.*,C.Name ,A.PPrice-A.PSelPrice as DiscAmount,B.Name as ImageName, C.Name as BrandName from tblProducts A
inner join tblBrands C on C.BrandID =A.PBrandID
cross apply(
select top 1 * from tblProductImages B where B.PID= A.PID order by B.PID desc
)B
order by A.PID desc
Return 0
---------3
create function getSizeName
(
@SizeID int
)
RETURNS Nvarchar(10)
as
Begin
Declare @SizeName nvarchar(10)
select @SizeName=SizeName from tblSizes where SizeID=@SizeID
RETURN @SizeName
End
---4
CREATE PROCEDURE SP_BindAllProducts
AS
SELECT A.*, B.*,C.Name, A.PPrice-A.PSelPrice AS DiscAmount, B.Name AS ImageName, C.Name AS BrandName FROM tblProducts A
INNER JOIN tblBrands C ON C.BrandID = A.PBrandID
CROSS APPLY(
SELECT TOP 1 * FROM tblProductImages B WHERE B.PID = A.PID ORDER BY B.PID DESC
)B
ORDER BY A.PID DESC
---5
create PROCEDURE SP_BindCartNumberz
(
@UserID int
)
AS
SELECT * FROM tblCart D CROSS APPLY ( SELECT TOP 1 E.Name,Extention FROM tblProductImages E WHERE E.PID = D.PID) Name where D.UID = @UserID
---6
create PROCEDURE SP_BindCartProducts
(
@UID int
)
AS
SELECT PID FROM tblCart WHERE UID = @UID
---7
CREATE PROCEDURE SP_BindPriceData
(
@UserID int
)
AS
SELECT * FROM tblCart D CROSS APPLY ( SELECT TOP 1 E.Name,Extention FROM tblProductImages E WHERE E.PID = D.PID) Name where D.UID = @UserID
---8
CREATE PROCEDURE SP_BindProductDetails
(
@PID int
)
AS
SELECT * FROM tblProducts where PID = @PID
---9
create PROCEDURE SP_BindProductImages
(
@PID int
)
AS
SELECT * FROM tblProductImages where PID = @PID
---10
create PROCEDURE SP_BindUserCart
(
@UserID int
)
AS
SELECT * FROM tblCart D CROSS APPLY ( SELECT TOP 1 E.Name,Extention FROM tblProductImages E WHERE E.PID = D.PID) Name WHERE D.UID = @UserID
---11
CREATE PROCEDURE SP_DeleteThisCartItem
@CartID int
AS
BEGIN
DELETE FROM tblCart WHERE CartID = @CartID
END
---12
CREATE PROCEDURE SP_EmptyCart
@UserID int
AS
BEGIN
DELETE FROM tblCart WHERE UID = @UserID
END
---13
CREATE PROCEDURE SP_FindOrderNumber @FindOrderNumber nvarchar(100)
AS
SELECT * FROM tblOrders WHERE OrderNumber = @FindOrderNumber
---14
CREATE PROCEDURE SP_getUserCartItem
(
@PID int,
@UserID int
)
AS
SELECT * FROM tblCart WHERE PID = @PID AND UID = @UserID
---15
CREATE PROCEDURE SP_InsertCart
(
@UID int,
@PID int,
@PName nvarchar(MAX),
@PPrice money,
@PSelPrice money,
@Qty int
)
AS
INSERT INTO tblCart VALUES(@UID,@PID,@PName,@PPrice,@PSelPrice,@Qty)
SELECT SCOPE_IDENTITY()
---16
CREATE PROCEDURE SP_InsertOrder
(
@UserID int,
@Email nvarchar(MAX),
@CartAmount money,
@CartDiscount money,
@TotalPaid money,
@PaymentType nvarchar(50),
@PaymentStatus nvarchar(50),
@DateOfPurchase datetime,
@Name nvarchar(200),
@Address nvarchar(MAX),
@MobileNumber nvarchar(50),
@OrderStatus nvarchar(50),
@OrderNumber nvarchar(50)
)
AS
INSERT INTO tblOrders VALUES(@UserID,@Email,@CartAmount,@CartDiscount,@TotalPaid,@PaymentType,@PaymentStatus,@DateOfPurchase,@Name,@Address,@MobileNumber,@OrderStatus,@OrderNumber)
SELECT SCOPE_IDENTITY()
---17
CREATE PROCEDURE SP_InsertOrderProducts
(
@OrderID nvarchar(50),
@UserID int,
@PID int,
@Products nvarchar(MAX),
@Quantity int,
@OrderDate datetime,
@Status nvarchar(100)
)
AS
INSERT INTO tblOrderProducts VALUES (@OrderID,@UserID,@PID,@Products,@Quantity,@OrderDate,@Status)
SELECT SCOPE_IDENTITY()
----18
CREATE PROCEDURE SP_IsProductExistInCart
(
@PID int,
@UserID int
)
AS
SELECT * FROM tblCart where PID = @PID and UID = @UserID
----19
CREATE PROCEDURE SP_UpdateCart
(
@UserID int,
@CartPID int,
@Quantity int
)
AS
BEGIN
SET NOCOUNT ON;
UPDATE tblCart SET Qty = @Quantity WHERE PID = @CartPID AND UID = @UserID
END
go
-----------------------
------------
create procedure [dbo].[procBindAllProducts2]
AS
select A.*,B.*,C.Name ,A.PPrice-A.PSelPrice as DiscAmount,B.Name as ImageName, C.Name as BrandName
from tblProducts A
inner join tblBrands C on C.BrandID =A.PBrandID
inner join tblCategory as t2 on t2.CatID=A.PCategoryID
cross apply(
select top 1 * from tblProductImages B where B.PID= A.PID order by B.PID desc
)B where t2.CatName='Shirt'
order by A.PID desc
Return 0
---------------
create procedure [dbo].[procBindAllProductsWomanTop]
AS
select A.*,B.*,C.Name ,A.PPrice-A.PSelPrice as DiscAmount,B.Name as ImageName, C.Name as BrandName
from tblProducts A
inner join tblBrands C on C.BrandID =A.PBrandID
inner join tblCategory as t2 on t2.CatID=A.PCategoryID
cross apply(
select top 1 * from tblProductImages B where B.PID= A.PID order by B.PID desc
)B where t2.CatName='Top' OR t2.CatName='Kurtas Kurtis'
order by A.PID desc
Return 0
---------------------------------
select * from tblBrands
insert into tblBrands values('BESPOQE ')
insert into tblBrands values('HIGHLANDER ')
insert into tblBrands values('FASHION DEPTH ')
insert into tblBrands values('OOMPH ')
select * from tblCategory
INSERT into tblCategory values('TShirt')
INSERT into tblCategory values('Shirt')
INSERT into tblCategory values('Kurtas Kurtis')
INSERT into tblCategory values('Top')
select * from tblSubCategory
insert into tblSubCategory values('Casual',2)
insert into tblSubCategory values('Formal',2)
insert into tblSubCategory values('Kurtis',3)
insert into tblSubCategory values('Casual',4)
select * from tblGender
insert into tblGender values('Male')
insert into tblGender values('Female')
select * from tblProducts
insert into tblProducts values('BESPOQE Men Regular Fit Solid Casual Shirt',1899.00,799.00,1,2,3,1,'For the best fit, buy one size larger than your usual size.','For the best fit, buy one size larger than your usual size.','For the best fit, buy one size larger than your usual size.',1,1,1)
insert into tblProducts values('HIGHLANDER Men Slim Fit Checkered Spread Collar Casual Shirt',1299.00,546.00,2,2,1,1,'Product Details Pack of 1 Style Code HLSH010263 Fit Slim Fabric Cotton Blend Sleeve Full Sleeve Pattern Checkered Reversible No Collar Spread Color Green, Black Fabric Care Gentle Machine Wash Suitable For Western Wear Hem Curved','100% cotton','100% cotton',1,1,1)
insert into tblProducts values('FASHION DEPTH Women Embroidered Rayon Straight Kurta (Pink)',1699.00,649.00,3,3,4,2,'Product Details Ideal For Women Length Type Calf Length Brand Color Pink Occasion Casual Pattern Embroidered Type Straight Fabric Rayon Neck Round Neck','Product Details Ideal For Women Length Type Calf Length Brand Color Pink Occasion Casual Pattern Embroidered Type Straight Fabric Rayon Neck Round Neck','100% cotton',1,1,1)
insert into tblProducts values('Oomph! Casual Butterfly Sleeve Floral Print Women Multicolor Top',1330.00,450.00,4,4,5,2,'Casual Butterfly Sleeve Floral Print Women Multicolor Top','Product Details Neck Round Neck Sleeve Style Butterfly Sleeve Fit Relaxed Fabric Poly Crepe Type Regular Top Belt Included No Pattern Floral Print Color Multicolor','100% cotton',1,1,1)
select * from tblProductImages
insert into tblProductImages values(1,'BESPOQE Men Regular Fit Solid Casual Shirt01','.jpeg')
insert into tblProductImages values(1,'BESPOQE Men Regular Fit Solid Casual Shirt01','.jpeg')
insert into tblProductImages values(1,'BESPOQE Men Regular Fit Solid Casual Shirt01','.jpeg')
insert into tblProductImages values(1,'BESPOQE Men Regular Fit Solid Casual Shirt01','.jpeg')
insert into tblProductImages values(1,'BESPOQE Men Regular Fit Solid Casual Shirt01','.jpeg')
insert into tblProductImages values(2,'HIGHLANDER Men Slim Fit Checkered Spread Collar Casual Shirt01','.jpeg')
insert into tblProductImages values(2,'HIGHLANDER Men Slim Fit Checkered Spread Collar Casual Shirt01','.jpeg')
insert into tblProductImages values(2,'HIGHLANDER Men Slim Fit Checkered Spread Collar Casual Shirt01','.jpeg')
insert into tblProductImages values(2,'HIGHLANDER Men Slim Fit Checkered Spread Collar Casual Shirt01','.jpeg')
insert into tblProductImages values(2,'HIGHLANDER Men Slim Fit Checkered Spread Collar Casual Shirt01','.jpeg')
insert into tblProductImages values(3,'FASHION DEPTH Women Embroidered Rayon Straight Kurta (Pink)01','.jpeg')
insert into tblProductImages values(3,'FASHION DEPTH Women Embroidered Rayon Straight Kurta (Pink)01','.jpeg')
insert into tblProductImages values(3,'FASHION DEPTH Women Embroidered Rayon Straight Kurta (Pink)01','.jpeg')
insert into tblProductImages values(3,'FASHION DEPTH Women Embroidered Rayon Straight Kurta (Pink)01','.jpeg')
insert into tblProductImages values(3,'FASHION DEPTH Women Embroidered Rayon Straight Kurta (Pink)01','.jpeg')
insert into tblProductImages values(4,'Oomph! Casual Butterfly Sleeve Floral Print Women Multicolor Top01','.jpeg')
insert into tblProductImages values(4,'Oomph! Casual Butterfly Sleeve Floral Print Women Multicolor Top01','.jpeg')
insert into tblProductImages values(4,'Oomph! Casual Butterfly Sleeve Floral Print Women Multicolor Top01','.jpeg')
insert into tblProductImages values(4,'Oomph! Casual Butterfly Sleeve Floral Print Women Multicolor Top01','.jpeg')
insert into tblProductImages values(4,'Oomph! Casual Butterfly Sleeve Floral Print Women Multicolor Top01','.jpeg')
select * from tblProductSizeQuantity
insert into tblProductSizeQuantity values(1,1,10)
insert into tblProductSizeQuantity values(2,3,12)
insert into tblProductSizeQuantity values(3,4,12)
insert into tblProductSizeQuantity values(4,5,10)
select * from tblPurchase
select * from tblSizes
insert into tblSizes values('Large',1,2,1,1)
insert into tblSizes values('Small',2,2,1,1)
insert into tblSizes values('Large',2,2,1,1)
insert into tblSizes values('Large',3,3,4,2)
insert into tblSizes values('Large',4,4,5,2)
select * from tblUsers
-------------------------
create procedure [dbo].[procBindAllProducts3]
AS
select A.*,B.*,C.Name ,A.PPrice-A.PSelPrice as DiscAmount,B.Name as ImageName, C.Name as BrandName
from tblProducts A
inner join tblBrands C on C.BrandID =A.PBrandID
inner join tblCategory as t2 on t2.CatID=A.PCategoryID
cross apply(
select top 1 * from tblProductImages B where B.PID= A.PID order by B.PID desc
)B where t2.CatName='Pants' or t2.CatName='Jeans'
order by A.PID desc
Return 0
------
create procedure [dbo].[procBindAllProducts4]
AS
select A.*,B.*,C.Name ,A.PPrice-A.PSelPrice as DiscAmount,B.Name as ImageName, C.Name as BrandName
from tblProducts A
inner join tblBrands C on C.BrandID =A.PBrandID
inner join tblCategory as t2 on t2.CatID=A.PCategoryID
cross apply(
select top 1 * from tblProductImages B where B.PID= A.PID order by B.PID desc
)B where t2.CatName='Jeans' or t2.CatName='Denim Jeans'or t2.CatName='Pants'
order by A.PID desc
Return 0
-------------
create procedure [dbo].[procBindAllProducts4]
AS
select A.*,B.*,C.Name ,A.PPrice-A.PSelPrice as DiscAmount,B.Name as ImageName, C.Name as BrandName
from tblProducts A
inner join tblBrands C on C.BrandID =A.PBrandID
inner join tblCategory as t2 on t2.CatID=A.PCategoryID
cross apply(
select top 1 * from tblProductImages B where B.PID= A.PID order by B.PID desc
)B where t2.CatName='Jeans'
order by A.PID desc
Return 0
-----------------
create procedure [dbo].[procBindAllProducts5]
AS
select A.*,B.*,C.Name ,A.PPrice-A.PSelPrice as DiscAmount,B.Name as ImageName, C.Name as BrandName
from tblProducts A
inner join tblBrands C on C.BrandID =A.PBrandID
inner join tblCategory as t2 on t2.CatID=A.PCategoryID
cross apply(
select top 1 * from tblProductImages B where B.PID= A.PID order by B.PID desc
)B where t2.CatName='Leggings' or t2.CatName='Leggings Western Wear'
order by A.PID desc
Return 0
-------------
create procedure [dbo].[procBindAllProducts6]
AS
select A.*,B.*,C.Name ,A.PPrice-A.PSelPrice as DiscAmount,B.Name as ImageName, C.Name as BrandName
from tblProducts A
inner join tblBrands C on C.BrandID =A.PBrandID
inner join tblCategory as t2 on t2.CatID=A.PCategoryID
cross apply(
select top 1 * from tblProductImages B where B.PID= A.PID order by B.PID desc
)B where t2.CatName='SAREES'
order by A.PID desc
Return 0
----------------------