Using variable in the Like Search
Hello,
I am having some trouble in writing the query for the below requirement.
I have a variable @LineName whose value is 'WEP3' and the datatype is varchar(50).
I have a table called CacheStore which has the below columns
ID SearchWord
1 Ant
2 WEP
3 WE
Now I want to know the search words which are similar to @LineName value. In the output, When I write a query I just want to see
ID SearchWord
2 WEP
3 WE
The bottom line is I want to get the records from CacheStore table which are similar to the @LineName value.
Please help me with the query. Thank you so much.
Thank you all for your replies. The above proposed solution partially resolved my issue. But I am still seeing some problem.
I have a search word in the cachestore table which is 'WEP3-SEG-1'
When I execute the below query, I am expecting to see 'WEP3-SEG-1' in the output
Declare @LineName varchar(50) = 'WEP3-SEG-1A'
Select * From
CacheStore where @LineName like
'%' + SearchWord
+ '%'
But I am getting all the below search words along with 'WEP3-SEG-1'
ID SearchWord
2 P
3 %
4 -
5 3
6 'WEP3-SEG-1'
I just want to see this in the output
ID SearchWord
6 'WEP3-SEG-1'
How to achieve this? Thanks again for all your help.
Similar Messages
-
How to use variable in the LIKE function along with % operators
Hi,
Is there any way i can use the variable in the Like function. That means i have query like
SELECT * FROM Device WHERE DeviceName LIKE %v_MediaName%;
Here "v_MediaName" is the userdefined variable which contains string. I want to retrieve all the records from the "DEVICE" table whose DeviceName LIKE %v_MediaName%;
If i put it in a single quotes '%v_MediaName%' then the v_MediaName will be treaded as a string instead of a variable. I am using this query in a Procedure.
please help me out to resolve the issue.
thanksLIKE '%'||v_MediaName||'%';
Will not make use of the indexes though.
Message was edited by:
satishkandi -
Using variables in the title of the graph
Hi Gurus,
I would like to use - for example a presentation- variable in the title of a graph.
I assign a value for that variable in dashboard prompt.
Does anybody know the syntax of using variable in the title of a graph
(Not in a Title view!)
Thanks in advance .
Regards
LaszloYou can reference presentation variables in the following areas :
Title Views
Narrative Views
Column Filters
Column Formulas
Conditional Formatting conditions
Chart scale markers.
Gauge range settings.
Static text.
Direct Database Requests
Dashboard prompts
iBot Headlines and text -
SPSiteDataQuery - filter by file Title - Can I use variable for the filter value?
I use SPsiteDataQuery to search across multiple lists and filter by file title. I have the file title information in a variable.
Can I use variable in the filter value?
string fileName = "Policies.doc"
SPSiteDataQuery spQry = new SPSiteDataQuery();
spQry.ViewFields = "<FieldRef Name='Title'/><Value Type='Text'>fileName</Value>"If I have understood correctly, you want to search based upon a File title in all the sites. You can include a query to filename in the spQry
spQry.Query = "<Where>" +
"<Eq>" +
"<FieldRef Name=\"FileLeafRef\"/>" +
"<Value Type=\"Text\">" + fileName + "</Value>" +
"</Eq>" +
"</Where>";
get2pallav
Please click "Propose As Answer" if this post solves your problem or "Vote As Helpful" if this post has been useful to you. -
Using variable with the same name as field name?
I have a complex proc where I have variables with the same name as field name used on a query. something like this:
SELECT a.id_table WHERE a.id_table = id_table
where the last id_table is a parameter sent to the proc:
declare procedure myproc(id_table int)
Is there any way or notation to declare the variable inside the query as a variable or I have to use a different name?Well, variables are not the only thing you have to change if you want to switch to Oracle.
Although I don't think it is good practice (to use variable name same as column name), here is one example how you can achieve it using EXECUTE IMMEDIATE and bind variable
SQL> select deptno, count(1)
2 from scott.emp
3 group by deptno;
DEPTNO COUNT(1)
30 6
20 5
10 3
SQL> set serveroutput on
SQL> declare
2 deptno varchar2(10);
3 i number;
4 begin
5 deptno:=10;
6 execute immediate
7 'select count(1) from scott.emp where deptno=:deptno' into i using deptno;
8 dbms_output.put_line('OUT ---> '||i);
9 end;
10 /
OUT ---> 3
PL/SQL procedure successfully completed.
SQL> Message was edited by:
tekicora
Message was edited by:
tekicora -
How is it possible to use Index Seek for LIKE %search-string% case?
Hello,
I have the following SP:
CREATE PROCEDURE dbo.USP_SAMPLE_PROCEDURE(@Beginning nvarchar(15))
AS
SELECT * FROM HumanResources.Employee
WHERE NationalIDNumber LIKE @Beginning + N'%';
GO
If I run the sp first time with param: N'94', then the following plan is generated and added to the cache:
SQL Server "sniffs" the input value (94) when compiling the query. So for this param using Index Seek for AK_Employee_NationalIDNumber index will be the best option. On the other hand, the query plan should be generic enough to be able to handle
any values specified in the @Beginning param.
If I call the sp with @Beginning =N'%94':
EXEC dbo.USP_SAMPLE_PROCEDURE N'%94'
I see the same execution plan as above. The question is how is it possible to reuse this execution plan in this case? To be more precise, how
Index Seek can be used in case LIKE %search-string% case. I expected that
ONLY Index Scan operation can be used here.
AlexeyThe key is that the index seek operator includes both seek (greater than and less than) and a predicate (LIKE). With the leading wildcard, the seek is effectively returning all rows just like a scan and the filter returns only rows matching
the LIKE expression.
Do you want to say that in case of leading wildcard, expressions Expr1007 and Expr1008 (see image below) calculated such a way that
Seek Predicates retrieve all rows from the index. And only
Predicate does the real job by taking only rows matching the Like expression? If this is the case, then it explains how
Index Seek can be used to resolve such queries: LIKE N'%94'.
However, it leads me to another question: Since
Index Seek in
this particular case scans
all the rows, what is the difference between
Index Seek and Index Scan?
According to
MSDN:
The Index Seek operator uses the seeking ability of indexes to retrieve rows from a nonclustered index.
The storage engine uses the index to process
only those rows that satisfy the SEEK:() predicate. It optionally may include a WHERE:() predicate, which the storage engine will evaluate against all rows that satisfy the SEEK:() predicate (it does not use the indexes to do this).
The Index Scan operator retrieves
all rows from the nonclustered index specified in the Argument column. If an optional WHERE:() predicate appears in the Argument column, only those rows that satisfy the predicate are returned.
It seems like Index Scan is a special case of Index Seek,
which means that when we see Index Seek in the execution plan, it does NOT mean that storage engine does NOT scan all rows. Right?
Alexey -
I want to use SCCM 2012 R2 and OSD, to boot a bare metal machine, install and OS, and bind it to Active Directory. The catch is that I want the deployment process in SCCM to prompt for the following pieces of information, and then use that information to
bind the computer to Active Directory (W/O using MDT) instead of supply the data in the task sequence.
Computer Name
Domain
Domain OU
Domain Join Account
I am approaching this in a similar fashion as stated in this blog.
http://osdblog.com/2013/06/26/add-a-prompt-for-a-computer-name-in-your-sccm-deployment/
I have added the following collection variables to the unknown computers collection:
When I launch the task sequence, I am prompted as I would expect. I input the desired information, the deployment competes, but it does not bind to the domain. Here is what my TS looks like. I intentally disabbled the apply Network Settings step
because it forces you to enter specific information if it enabled. I don't want to that, thus why I am trying to use the variables.
My SMSTS log does not have a whole lot of meaningfull data, but I can post it if someone wants to see it. The only possible thing I could think of would be drivers, their are some driver errors in the log. However, if I turn on the Apply Networking setting
process in the task sequence and turn off the variables, the machines bind fine. With that in mind, I would not think my problem would be driver related. Anyone out there have expertise in using a process like this, that could assist?
--TonyAwesome! Thanks. One more thing, how should I supply the OSDJoinPassword variable? Should I just enter %OSDJoinPassword%
for Password and Confirm Password? I can not tell if it will actually read it as a variable or try to use "%OSDJoinPassword%" for
the actual password.
--Tony -
I'd like to change the main search engine to something else, like DuckDuckGo. thank you
Current Firefox versions use the default search engine (pref: browser.search.defaultenginename) to set the search engine that is used on the about:home page.
You can modify the <b>browser.search.defaultenginename</b> pref on the <b>about:config</b> page and set it to one of the other installed search engines.
Select this search engine in Manage Search Engines and copy the value of the browser.search.selectedEngine pref to browser.search.defaultenginename.
*browser.search.defaultenginename
*browser.search.selectedEngine -
Query Stripping not working properly when using variable in the report
We have issue with WEBI document that have query stripping enable.
Once the query stripping enabled there is no data return in the report.
We have investigate on the problem, the query stripping function are notable to retrieve objects that indirectly used in the report
as we have
many variable in the reports.
Ex.
Var1 = object1 + object2
Var2 = Object3 + Object4
Var3 = Var1 + Var2
Var4 = Object1 + Object2 + Object3 + Object4
If we use only Var3 in the report, the object1,2,3,and 4 will not be
retrieve.
But if we are using Var4 in the report, the object1,2,3,and 4 will be
retrieve properly.
Please let me know is it a by-design behavior, if yes please share points on itHi Amit,
Thank you for response, however i already had alook on that VIdeo and it tells us about the basic enabling of query stripping.
But my question is when we have a Variable in a report which is dependent on the other two variables it gives me #error so is it by design or not.
Regards,
Abhinav -
Using variables in the Query Designer
Hi,
I have 2 variables 'Z_COMP_CODE' and 'Z_BUS_AREA'. The type of 'Z_COMP_CODE' is single value ,customer exit and ready for input . The type of 'Z_BUS_AREA' is selection option,customer exit and not ready for input. I want the 2 variables to work like this: when 'Z_COMP_CODE' has the value '3000', 'Z_BUS_AREA' should have all the values excluding '2106'. Now in CMOD I have written the following codes for 'Z_BUS_AREA', But it does not work. 'Z_BUS_AREA' get no value while the query is running.Can somebody tell me how to correct it?thx.
WHEN 'Z_BUS_AREA'.
IF i_step = 2.
READ TABLE i_t_var_range INTO l_s_range_v
WITH KEY vnam = 'Z_COMP_CODE'.
IF sy-subrc EQ 0.
IF l_s_range_v-low = '3000'.
l_s_range-low = '2106'.
l_s_range-sign = 'E'.
l_s_range-opt = 'EQ'.
INSERT l_s_range INTO TABLE e_t_range.
ENDIF.
ENDIF.
ENDIF.It should be Customer Exit only.
Your code looks like ok to me. Have you tried to debug it? is l_s_range taking values?
Also i don't know much abt insert statement...may be same as append...but just try with append statement also.
Message was edited by:
KJ (Kamaljeet) -
Using a variable in the 'LIKE' part of a WHERE clause
How would I go about achieving this?
I have SELECT...WHERE person_number LIKE '123%';
While keeping the percent symbol, how would I substitute and explicit value with an implicit reference to a variable I have already assigned a value to?
Thanks a lot.not sure if this is what you require, but you can simply concatenate your variable with '%'
for example;
SQL> select * from emp1 where job like 'A%';
EMPNO JOB START_DAT SAL DEPT
3 Author
4444 AUTHOR 24-MAY-10 5001 3
3333 ANALYST 24-MAY-09 5004 2
SQL> variable prefix char(1);
SQL> exec :prefix :='A';
SQL> select * from emp1 where job like :prefix||'%';
EMPNO JOB START_DAT SAL DEPT
3 Author
4444 AUTHOR 24-MAY-10 5001 3
3333 ANALYST 24-MAY-09 5004 2 -
Using Variable in the Data Template
Hi All,
I am on BIP 10.1.3.4.1 and DB is SQL Server. My Data Model is a Data Template wherein I have written multiple SQL Statements. I want to use a variable in my Data Template, assign it a value and use that variable to limit one of the SQL statements in the where clause like
declare @cnt int;
set @cnt = select count(asset_id) from asset
How do I use in the data template. I tried using it in a separate SQL statement but it throws me an error when i run the report like
"Need to declare the scalar variable '@cnt'
Can we have a variable section like parameter section we have in the data template to declare the parameters?
Any help would be highly appreciated.
Thanks,
RonnySorry for the shot follow up, can anybody please reply on this?
-
Using variables in the SQL Results in Dashboard Prompt
I use the ff query to limit my results on my dashboard prompt. The variable value is given by a dashboard prompt within the same page.
SELECT Owner.Name saw_0 FROM "iSupport Service Request" WHERE "- Service Request Attributes".Platform =
'@{promptedPlatform}' ORDER BY saw_0
It works fine with this query, only when selecting a particular selection in the prompt that feeds the variable data. Is there anyway to have this particular prompt by default(when the page first loads, load all the values possible prior to filtering by the variable?Hi Harley ,
The frame labels are 1,2,3 etc
sym.setVariable("subselect" , 0); // in the stage composition ready
Then in the menu you can set the "subselect" variable to 1,2,3 and then call sym.play(sym.getVariable("subselect"));
Thanks and Regards,
Sudeshna Sarkar -
Using Variables in the sym.play statement
I have built a menu system consisting of a main menu with three options and a single sub-menu animation that should stop at one of three different spots on the timeline depending on which main menu button is clicked.
For each main menu button I have created a click event consisting of sym.setVariable("subselect", "#"); where "#" can be set to 1, 2 or 3. When any one of the main menu buttons is clicked, the sub-menu opens and at the end of that sequence I have inserted the following - sym.play(subselect);
This is all pretty clearly displayed in the annotated screen snap below.
It's important for me to master the use of varaibles and concatenated strings in the sym.play statement so I can create as compact OAM files as possible so any help is greatly appreciated. My guess is that i'm making a stupid syntax error, but I'm not opposed to picking other people's brains when mine proves inadequate for the task at hand.
Thanks very much.
Andy.Hi Harley ,
The frame labels are 1,2,3 etc
sym.setVariable("subselect" , 0); // in the stage composition ready
Then in the menu you can set the "subselect" variable to 1,2,3 and then call sym.play(sym.getVariable("subselect"));
Thanks and Regards,
Sudeshna Sarkar -
How to use variables in the mail text while sending mails through workflows
Dear All,
I had prepared a workflow in which i am sending mail to a administrator if personnel data of any employee is changed.But i want to send the personnel no of employee whose data have been changed.How can i send this personnel no in the mail.
Points will be rewarded for useful answer.Hi Anand,
You have the "EmployeeNumber" field in the event container. Pass this into the workflow container by defining a Workflow Container element and subsequently use this container as a variable in your email using insert fields option and you will have the PersonNumber visible in your mail sent to the administrator.
Regards,
Karthik
Maybe you are looking for
-
Is it possible to add a word doc (as a separate file) in Captivate?
This could help to satisfy 508 compliance. This is in addition to the closed captioning feature, which I plan to incorporate. FYI - I used Articulate Presenter in the past and was able to attach a Word Document, which user was able to access via link
-
I have an alias file that will not delete or drag and it will not open to original file. I have tried everything I know and they still wont delete. Can someone please help me?
-
Can I set up AirportExpress for iPad2 without needing to use MacBook
I want to use my iPad2 with hotel Ethernet cable with out requiring my MacBook. Is a computer required to set up the AirPort Express or can it be done from iPad2
-
It says there is a problem with the licensing of the program. I reinstalled it on my laptop after it went for repairs and got a new hard drive.
-
NVIDIA QUANDRO FX 540 CODE 35 ON XW4300 WORKSTATION
ON THIS XW 4300 WORKSTATION RUNNING WINDOWS 7 64 BIT. ULT. THERE IS A CODE 35 ON THE QUANDRO FX540 THE BIOS VERSION I SEE IS 786D3 VOL.05 (don't really what that is) compared to what I see on the website. LAST THING I TRIED WAS TO DOWNLOAD THE DRIVE