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 |
|
rogerclerkwell
Yak Posting Veteran
85 Posts |
Posted - 2011-10-12 : 11:30:11
|
| I have a filter table that some idiot, don't know who, has setup with filters in it eg <> or &= and I need to use these in sql but not sure if this is possible or not, and if it is, is it going to be a complete nightmare to workout...eg the tableDescription StyleGroup ItemCodeTROUSERS 101 JUMPERS 102 SHIRTS 105 <>5647SHIRTS COTTON 105 =5647JACKETS 106 SUITS 108 <>1245&<>5465SUITS VELVET 108 =1245&=5465I need to uddate another table with the descriptions linking on StyleGroup, but then also on ItemCode, wondering if this should bein 2 steps eg-- first updateUPDATE [TheBud2]SET [TheBud2].[Description] = b.[Description]FROM [TheBud] bWHERE [TheBud2].[StyleGroup] = b.[StyleGroup]then a second to workout the stylesIt needs to look at the item code filter soif StyleGroup = 105 but the ItemCode in update table = 5647 don't put SHIRTS becaus eof this filter <>5647.But below line if StyleGroup = 105 and itemcode =5647 then put SHIRTS COTTON.eg table would look something like this at the end:Description StyleGroup ItemCodeTROUSERS 101 1099SHIRTS COTTON 105 5647SHIRTS 105 1004TROUSERS 101 1099JUMPERS 102 1004SUITS 108 1003SUITS VELVET 108 1245SUITS VELVET 108 5465SUITS 108 1002Or is can;t do it with a sql maybe split the filters and date out intoanother temp table and then update joining to this table.ARRGGHHH I'm going mad with this thing, sat here for hours trying to work it out.Any help would be greatCheers,RogerCreate tables and test data:--TablesCREATE TABLE [dbo].[TheBud]( [Description] [varchar](30) NOT NULL, [StyleGroup] [varchar](30) NOT NULL, [ItemCode] [varchar](20) NOT NULL)GOCREATE TABLE [dbo].[TheBud2]( [Description] [varchar](30) NOT NULL, [StyleGroup] [varchar](30) NOT NULL, [ItemCode] [varchar](20) NOT NULL)GO--Insert into Table 1INSERT INTO [TheBud]([Description],[StyleGroup],[ItemCode])VALUES('TROUSERS','101','')GOINSERT INTO [TheBud]([Description],[StyleGroup],[ItemCode])VALUES('JUMPERS','102','')GOINSERT INTO [TheBud]([Description],[StyleGroup],[ItemCode])VALUES('SHIRTS','105','<>5647')GOINSERT INTO [TheBud]([Description],[StyleGroup],[ItemCode])VALUES('SHIRTS COTTON','105','=5647')GOINSERT INTO [TheBud]([Description],[StyleGroup],[ItemCode])VALUES('JACKETS','106','')GOINSERT INTO [TheBud]([Description],[StyleGroup],[ItemCode])VALUES('SUITS','108','<>1245&<>5465')GOINSERT INTO [TheBud]([Description],[StyleGroup],[ItemCode])VALUES('SUITS VELVET','108','=1245&=5465')GO-- Insert into Table 2INSERT INTO [TheBud2]([Description],[StyleGroup],[ItemCode])VALUES('','101','1099')GOINSERT INTO [TheBud2]([Description],[StyleGroup],[ItemCode])VALUES('','105','5647')GOINSERT INTO [TheBud2]([Description],[StyleGroup],[ItemCode])VALUES('','105','1004')GOINSERT INTO [TheBud2]([Description],[StyleGroup],[ItemCode])VALUES('','108','1003')GOINSERT INTO [TheBud2]([Description],[StyleGroup],[ItemCode])VALUES('','108','1245')GOINSERT INTO [TheBud2]([Description],[StyleGroup],[ItemCode])VALUES('','108','5465')GOINSERT INTO [TheBud2]([Description],[StyleGroup],[ItemCode])VALUES('','108','1002')GO |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-10-12 : 11:53:20
|
| Do you know how to use dynamic sql?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
rogerclerkwell
Yak Posting Veteran
85 Posts |
Posted - 2011-10-12 : 11:57:17
|
| dynamic sql not really, is this what is needed.I've setup a few stored procs with variables... |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2011-10-13 : 09:39:17
|
| Find out whoever decided to store the data this way, then lock them in a room with Joe Celko for a few hours. Justice will be served.Otherwise, not sure if Dynamic SQL would be needed.http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|
|
|
|