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.

 All Forums
 SQL Server 2008 Forums
 Analysis Server and Reporting Services (2008)
 MID function - comparing two fields

Author  Topic 

tech2
Yak Posting Veteran

51 Posts

Posted - 2014-04-24 : 16:14:20
I'm trying to create a calculated field.

I only want to include rows in field1 where 'Widget1' is included in the text in field2.

Thanks,

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-04-24 : 17:35:55
Not quite clear what the logic you are trying to implement is, but perhaps something like this?

CASE WHEN field2 LIKE '%Widget1%' THEN field1 ELSE NULL
or, may be
SELECT field1
FROM YourTable
WHERE field2 like '%Widget1%'
Go to Top of Page

tech2
Yak Posting Veteran

51 Posts

Posted - 2014-05-05 : 11:41:06
Example below: I hope this makes sense.

1. I have a 'note' field with an Item Number 'WIDGET1000'
2. I'm parsing 'WIDGET1000' with the first calculated field into a NEW Calculated field 'NotePartNum'
3. I then create another calculated field 'KEY', and run a 'LIKE' formula comparing 'PARTNUMBER' against 'NotePartNum' which gives me a 'TRUE' or 'FALSE'.

The problem is: ALL rows with 'ETA 5/7' are indicating 'FALSE'. Rows with no characters after 'WIDGET1000' are showing 'TRUE'? This is where I'm having my problem.

NOTE FIELD (NOTE) Calculated Field
ABC WIDGET1000 ETA 5/7 =Mid(Fields!NOTE.Value,5,10)

(KEY) Calculated Field
=(Fields!PARTNUMBER.Value)LIKE(Fields!NotePartNum.Value)

Thanks and any suggestions are highly appreciated.
Go to Top of Page
   

- Advertisement -