Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Analysis Server and Reporting Services (2008)
 MID function - comparing two fields
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tech2
Yak Posting Veteran

50 Posts

Posted - 04/24/2014 :  16:14:20  Show Profile  Reply with Quote
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,

Edited by - tech2 on 05/05/2014 13:27:51

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 04/24/2014 :  17:35:55  Show Profile  Reply with Quote
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

50 Posts

Posted - 05/05/2014 :  11:41:06  Show Profile  Reply with Quote
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.

Edited by - tech2 on 05/05/2014 13:31:30
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000