Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is this possible to do?

0 views
Skip to first unread message

Mangler

unread,
Nov 30, 2007, 5:22:22 PM11/30/07
to
I have the following table:

CREATE TABLE [dbo].[sku_info](
[idsku] [int] IDENTITY(1,1) NOT NULL,
[model_full] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
[model_short] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
[part_desc] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
[sku] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
CONSTRAINT [PK_sku_info] PRIMARY KEY CLUSTERED
(
[idsku] ASC
) ON [PRIMARY]
) ON [PRIMARY]

and some values :

INSERT INTO [reclaim_new].[dbo].[sku_info]
([model_full]
,[model_short]
,[part_desc]
,[sku])
VALUES
('Sanyo 2300 Silver'
,'2300'
,'Test'
,'123')
VALUES
('Sanyo 2300 Black/Silver'
,'2300'
,'Test1'
,'1234')
VALUES
('Sanyo 2300 Pink'
,'2300'
,'Test3'
,'12345')

I need to run a query that will pull all the SKU's that match for
example : Sanyo 2300 Silver


in the above case the results will show me : 123 , 1234 because the
model_full has Sanyo 2300 silver in it..... is this possible to do?
That model is just a variable so the next query could pull all the
SKU's where the model_full is like LG 225 Red...

Erland Sommarskog

unread,
Nov 30, 2007, 5:52:55 PM11/30/07
to
Mangler (dwal...@aspdevil.com) writes:
> I need to run a query that will pull all the SKU's that match for
> example : Sanyo 2300 Silver
>
>
> in the above case the results will show me : 123 , 1234 because the
> model_full has Sanyo 2300 silver in it..... is this possible to do?
> That model is just a variable so the next query could pull all the
> SKU's where the model_full is like LG 225 Red...

SELECT *
FROM sku_info
WHERE model_full LIKE '%' +replace('Sanyo 2300 Silver', ' ', '%') + '%'

Although it is not unlikely that you will come to the point where
you will need to use full-text indexing.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Mangler

unread,
Nov 30, 2007, 6:43:34 PM11/30/07
to
On Nov 30, 5:52 pm, Erland Sommarskog <esq...@sommarskog.se> wrote:

> Mangler (dwald...@aspdevil.com) writes:
> > I need to run a query that will pull all the SKU's that match for
> > example : Sanyo 2300 Silver
>
> > in the above case the results will show me : 123 , 1234 because the
> > model_full has Sanyo 2300 silver in it..... is this possible to do?
> > That model is just a variable so the next query could pull all the
> > SKU's where the model_full is like LG 225 Red...
>
> SELECT *
> FROM sku_info
> WHERE model_full LIKE '%' +replace('Sanyo 2300 Silver', ' ', '%') + '%'
>
> Although it is not unlikely that you will come to the point where
> you will need to use full-text indexing.
>
> --
> Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se
>
> Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...

> Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

Thank you sir! That did the trick.

0 new messages