There is a problem with doing project today,
There are product categories A,b,c top-level classification,
There are A1,A2,A3 subcategories below midterm a.
But A1 may belong to both A and B, and then my database is designed like this.
Id |
Name |
Parnet |
1 |
A |
0 |
2 |
B |
0 |
3 |
A1 |
1,2 |
|
|
|
If you want to query all the subclasses of a, check that the parent contains 1, so this is the way. Hehe,
There is no good way for the moment, welcome to make bricks ~ ~
In addition, this thing I want to get back to the value of bool, which brotherhood of hope to help solve ....
Copy Code code as follows:
SET ANSI_NULLS on
Go
SET QUOTED_IDENTIFIER ON
Go
/*
-- =============================================
--Author: < Rice >
--Create Date: <2011-10-19>
--Description: < query delimiter split data contains an item >
-- =============================================
*/
ALTER Function [dbo]. [Haskey] (@DataStr varchar, @key varchar (8))
returns int
As
Begin
DECLARE @return_str varchar (50)
DECLARE @isok bit
DECLARE @posi int
Set @isok = 0
--set @DataStr = ' A,aaaa,aaaddd,ffass '
--set @key = ' aaaa '
Set @DataStr = @DataStr + ', '
While Len (@DataStr) > 0 and @isok =0
Begin
Set @posi = charindex (', ', @DataStr)
Set @return_str = replace (substring (@DataStr, 1,charindex (', ', @DataStr)), ', ', ', '
Set @DataStr = substring (@DataStr, @posi +1,len (@DataStr))
if (@return_str = @key)
Begin
Set @isok =1
Break
End
End
Return @isok
End
Go