Instr() Equivalent In SQL Server
Jul 20, 2005
I am trying to convert a complex function from Oracle to SQL Server
and have come across Oracle's Instr() function. I see SQL Server has
CHARINDEX() which is similar, however it does not provide some key
functionality I need. Here is an example of the Oracle code:
if Instr( sTg , cDelim, 1, 3 ) > 0 then
sd := SubStr( sTg, Instr( sTg , cDelim, 1, 1 ) + 1, Instr( sTg,
cDelim, 1, 2 ) - Instr( sTg , cDelim, 1, 1 ) - 1)
end if;
Has anybody converted anything similar to this within SQL Server? Any
help is GREATLY appreciated!
Thanks.
View 5 Replies
ADVERTISEMENT
Feb 2, 2005
The syntax for Oracle's INSTR function is
instr (string1, string2, [start_position], [nth_appearance])
string1 is the string to search.
string2 is the substring to search for in string1.
start_position is the position in string1 where the search will start. This argument is optional. If omitted, it defaults to 1. The first position in the string is 1. If the start_position is negative, the function counts back start_position number of characters from the end of string1 and then searches towards the beginning of string1.
nth_appearance is the nth appearance of string2. This is optional. If omiited, it defaults to 1.
In SQL Server, we are having CHARINDEX and PATINDEX functions. But they will not accept the fourth paremeter (nth_appearance)
Do anybody know the solution for this ????
View 1 Replies
View Related
Oct 26, 2006
Hi,In SQL SERVER 2005 Database I have a field called MedNames with values such as "sodium % 34ml" "desx chloride 9 % 76ml"I need to return the words before and including % so "sodium % 34ml" should return ""sodium % " Is it possible to do it in a select statement? I need to populate a dropdownlist with the shortened names.Thanks
View 1 Replies
View Related
Oct 11, 2004
I am using the Instr(), Len(), and Mid() function in my SQL query and I keep getting errors stating those are not recognized functions. IS this correct? are there any equivelants?
thanks
View 2 Replies
View Related
Jan 29, 2001
Hello there...
I am looking for the function that is the same as InStr in Access for SQL server. I have a column that has format like this.. Lastname,Firstname Middlename...
This column doesn't separate each one of them. However I need to separate Lastname and Firstname and Middlename.. I was told that in Access there is function(InStr) that can find a position of comma and separate it as Lastname like that....
I was searching BOL but I couldn't find like this function in SQL Server..
So I need help:-))))
Because everybody has a different length of the lastname, I have a problem.
I can not use SUBSTRING or LEFT or RIGHT because of the varying position of comma ...
Thanks in advance
Jay
View 1 Replies
View Related
Dec 11, 2002
In VB there is InStr, in Excel you have SEARCH. what function can i use to search a string for a specific string. ie: how can i find where a space is in someones name?
our database has a table that is used for security. it contains a user code, user name and passcode. i need to split the username (currently forename and surname in same field) into two, around the space.
in VB i would write something like
strFName = left(<usernamefield>,InStr(1,<usernamefield>," ")-1)
to get the forename and similar to get the surname. how can i do this in SQL so that a view will supply the data apprpriately?
one of the reasons i want to do this is so that i can sort the users by surname! another is so that i can give options on their usercode - a combination of forename initial and 2 characters from surname.
any help welcomed.
View 4 Replies
View Related
Jan 20, 2006
is there a sql keyword for find or instr?
i have a field i wish to make into two and i need the position of a string "-" in the field so i can do a select right and copy that data to a new colm
View 1 Replies
View Related
Mar 21, 2007
TASK: At my work we want to categorize and summarize all our IIS web logs and make statistics from it and such. What I need to do is take the browser type from a certain column in the table. All the information is stored in 1 column, and I figure an instr function would be best to do this. I am new to SQL, so I was told to look up the cursor function. In summary, I want to take all the IIS data and match it up against a defined table and then have a sum function for each browser.
Here are some examples of what the column data looks like: (found in the [csMethod] column
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1)
Mozilla/4.0+(compatible;+MSIE+6.0;+Windows+NT+5.1;+SV1;+.NET+CLR+2.0.50727)
Mozilla/4.0+(compatible;+MSIE+7.0;+Windows+NT+5.1;+.NET+CLR+2.0.50727;+.NET+CLR+3.0.04506.30;+InfoPath.2;+.NET+CLR+1.1.4322)
Mozilla/5.0+(Windows;+U;+Windows+NT+5.1;+en-US;+rv:1.8.0.8)+Gecko/20061025+Firefox/1.5.0.8
I made a define table which lists an ID (primary key) and instr to search for as well as the full browser name. (define.browser)
DEFINE.BROWSER
ID# INSTR# BROWSER NAME
###############################
1___Opera+7_______Opera 7
2___Opera/9_______Opera 9
3___Safari/_______Safari
4___Firefox/1.0___Mozilla Firefox 1.0
5___Firefox/1.5___Mozilla Firefox 1.5
6___Firefox/2.0___Mozilla Firefox 2.0
7___MSIE+5.5______Microsoft Internet Explorer 5.5
8___MSIE+5________Microsoft Internet Explorer 5
9___MSIE+6________Microsoft Internet Explorer 6
10___MSIE+7________Microsoft Internet Explorer 7
11_________________OTHER BROWSER
I am having problems getting a cursor to work. Are there any good tutorials out there, or can anyone be of assistance. Thank you in advance.
View 1 Replies
View Related
Jul 20, 2005
Hi everybody,I was looking for an equivalent ORACLE INSTR Function in MSSQL but Idon´t found it and I don´t know if it exist so I must to write it andthis is the code. Maybe it will be helful to you:/************************************************** *************************Description:Looks for a string inside another string and returns an integerthat correspond to the position of first ocurrence.Parameters:Input:- strSource. Contains the string where the functions look for theother string- strToFind. Contains the string to look for inside strSourceSalida:- Integer value indicating the position of first occurrence ofstrToFind in strSource************************************************** *************************/CREATE FUNCTION posSubString(@strSource varchar(400),@strToFind varchar(200)) RETURNS intASBEGINDECLARE@position int,@maxPos int,@longSubStr int,@res int,@strSub varchar(200)SET @position = 0SET @res = 0SET @longSubStr = LEN(RTIRM(LTRIM(@strToFind)))SET @maxPos = LEN(@strSource) - @longSubStrWHILE (@position <= @strToFind)BEGINSET @strSub = SUBSTRING(@strSource, @position, @longSubStr)IF (@strToFind = @StrSub)BEGINSET @res = @position - 1RETURN @resENDELSESET @position = @position + 1ENDRETURN @resENDAlonso
View 1 Replies
View Related
May 1, 2007
Greetings All
I have some data-- specifically times for cell phone usage in the format of (7:00, 15:51, 1,200:45, etc). I need to find a way to remove the ":" and the ","-- sum the data and then return it to its previous format of (7:00, 15:51, 1,200:45, etc). Does anyone have some code they could post??
thanks as always
km
View 4 Replies
View Related
Sep 25, 2000
Hi
My question is about the INSTR function of MSAccess
I want to know
Goodbye at every
I would you like to know if in TransactSQL of SQLServer7 exist a function that return the position of a string into an other string .
that is a Instr function MSAccess like
INSTR([Start,]expression1,expression2[,Comparison])
I'm sorry for my bad English
Thank you for everything
Emiliano
View 2 Replies
View Related
Jan 15, 2001
I went to Microsoft to find some info about the function Instr. I need to
perform a search with a string similar to their example I found below. Can
anyone explain to me Microsoft's example?? I am little confused by the
parameters used and the explanation it gives back to me??
Dim SearchString, SearchChar, MyPos
SearchString ="XXpXXpXXPXXP" ' String to search in.
SearchChar = "P" ' Search for "P".
MyPos = Instr(4, SearchString, SearchChar, 1) ' A textual comparison
starting at position 4. Returns 6.
MyPos = Instr(1, SearchString, SearchChar, 0) ' A binary comparison
starting at position 1. Returns 9.
MyPos = Instr(SearchString, SearchChar) ' Comparison is binary by default
(last argument is omitted). Returns 9.
MyPos = Instr(1, SearchString, "W") ' A binary comparison starting at
position 1. Returns 0 ("W" is not found).
My problem is this:
I need to scan within SearchString for blanks/spaces characters. When I
find one, then place the values to the left and right of it in seperate
columns. For example, I would need to scan 'John Smith A' and then place
'John' in FirstName column, 'Smith' in LastName column, and 'A' in MidName
column.
I think this is how my code would read, but I am confused on how to place
the results into my table to the correct columns?
my search string would be SearchString = 'John Smith A'
my SearchChar would be SearchChar = ' ' (note I am searching for a
space/blank character)
So would then my code be like:
Dim SearchString, SearchChar, MyPos
SearchString = 'John Smith A'
SearchChar = ' '
MyPos = Instr(1, SearchString, SearchChar, 0)
How do I get whatever is returned from the Instr function to a column in a
table??
Any help would be great.
Rey
View 1 Replies
View Related
Jun 4, 2007
Hi All
My SQL is extremly rusted so I need some help with a very basic function. I have a character field which is built up using a category code + '-' + number. The problem I have is that the category codes are all different lengths and the items were added using 9 instead of 09. I'm trying to clean up the data so that the same item with e.g. category code DZ20 cannot be added as DZ20-1 and DZ20-01. How do I find the position of the '-' in the Query Analyser for MSSQL 2000?
View 1 Replies
View Related
Nov 18, 2015
I have a field that contains a town  ex : New York. Sometimes, the field will have brackets to be more specific ex: New York (Brooklyn). What I need is a formula that will return only "Brooklyn" if there are brackets or  the whole field if there are no brackets.Here's what I thought would do the trick :
=Iif(InStr(First(Fields!Ville.Value, "MW1R017A_IdentificationTravailleur_AdresseTravailleur"), "(") > 0,
Left(Split(First(Fields!Ville.Value, "MW1R017A_IdentificationTravailleur_AdresseTravailleur"), "(")(1), len(Split(First(Fields!Ville.Value, "MW1R017A_IdentificationTravailleur_AdresseTravailleur"), "(")(1)) - 1)
, First(Fields!Ville.Value, "MW1R017A_IdentificationTravailleur_AdresseTravailleur"))
So if InStr returns more than 0, meaning that I have brackets, I'll split at the "(", get the second part and remove the last character which is the closing bracket I don't want. If there is no bracket, I'll return the whole field.Somehow, when there is no bracket, my report overview shows me "#Error" as if the first Iif was true and what's in the true part is not actually possible, because it's trying to take the second part of a split that couldn't split because there is no bracket to split.
View 8 Replies
View Related
Jul 9, 2004
I have 2 SQL statements in Visual Basic(with sybase as backend)
1) "set option DBA.MAX_STATEMENT_COUNT = 1069999900"
2) "set option DBA.MAX_CURSOR_COUNT = 1069999900"
And when I migrated the DB from Sybase to SQL server and try to run the vb code it is giving me error in that SQL statement as MS SQL server might not be recognising the above two statements. Is there an equivalent of this in SQL server.
Thanks
View 1 Replies
View Related
Jul 13, 2004
Hi
So far, I have only used Access which has an autonumber data type so that in some of my tables the id is automatically generated.
I guess this is a simple question but is there an equivalent data type in sql server?
Thanks in advance.
View 1 Replies
View Related
Apr 21, 1999
In sql server 6.5, standard security......
Will i assign the SA rights to some one/login...?
wincy
View 1 Replies
View Related
Mar 8, 2005
what is the equivalent of val() function in SQL server?
and cstr() function
View 4 Replies
View Related
Apr 30, 2007
Hello MSSQL professionals,
Please tell me the equavalent of the below MySQL query in SQL Server.
create table temp1(variable1 varchar(24) character set latin1 not null default '')
Immediate help will be highly appreciated
View 2 Replies
View Related
Nov 3, 2005
In ORACLE, I can use DESCRIBE PS_JOB to see the columns for that record. What is the SQL-Server equivalent?
TIA,
Joe
View 5 Replies
View Related
Jun 11, 2007
Hello all,
I'm making a query for this application that is not in the same server where the database is located.
This query I can easily get results when making the query within the server:
USE ADW_Publish;
SELECT distinct b.Subject
FROM dbo.F_Class_Exam a
LEFT OUTER JOIN dbo.D_Course_Catalog b
ON a.Course_ID = b.Course_ID
WHERE a.Term = '$536870994$' AND a.Class_Exam_Type = 'FIN' AND b.Term = '$536870994$'
ORDER BY b.Subject
Here are the details:
Servername: SERVER01
What would an equivalent query be if I apply this to an external application (located outside the server?)
I've gotten some hints to use:
SELECT *
FROM OPENDATASOURCE('MSDASQL', 'DataSource=DataSourceName;UserID=User;Password=SomePassword').DBName.dbo.TableName
But I dont know how to apply the query above to use that..
Any thoughts? Or are there other ways of doing it?
Thanks!
View 5 Replies
View Related
Jul 23, 2005
I am migrating a student database from Access to SQL Server. In AccessI have a query that displays grade information (grades are calculatedon a 12-point scale). In the query I average the students' scores andstore it in a column called Avg. I look up and display the equivalentgrade letter using Access' DLookup function from a table calledGradeTable_tbl. Here is how it's built in Access:Grade: DLookUp("[grade_letter]","GradeTable_tbl","[grade_num]= " &Int([Avg]))Here is the structure of the GradeTable_tbl:grade_num grade_letter0 F1 F2 D-3 D......10 B+11 A-12 AHow would I do the same thing in SQL Server? I want my output to besomething like:Student Score1 Score2 Score3 Avg GradeBob 12 10 8 10 B+Nancy 12 11 11 11 A-etc...I appreciate your feedback!-Paul------"You never know enough to know you don't know"
View 3 Replies
View Related
Jul 20, 2005
All,Oracle 9i provides a "USING" clause option for inner joins, thatallows me to say:SELECT * FROM TBL1 JOIN TBL2 USING KeyColumnassuming KeyColumn is in both TBL1 and TBL2. This is HIGHLY desirablefor our software make use of, but we also support SQL Server. Thereis no USING option available, andSELECT * FROM TBL1 JOIN TBL2 ON TBL1.KeyColumn = TBL2.KeyColumncauses an ambiguous column error on KeyColumn.Is there any equivalent to this Oracle functionality on SQL Server?KingGreg
View 7 Replies
View Related
Aug 13, 2007
Hello,
I'm trying to build a integration service package importing data from XML files and directs this data to different MS SQL server 2005 Database tables.
Can someone suggest me what is equivalent(mapping) data type of DT_UI8 in Sql server 2005 for Integration Services.
Or how to consume DT_UI8 fields in SQL server 2005.
View 2 Replies
View Related
May 22, 2007
Hi,
I've been looking for the equivalent of the MS Access 2003 field caption property in SQL but it appears as though there isn't one.
(The caption property gives a friendly name on form labels rather than the field name)
How would I do this in SQL so I don't have to overtype all the column names? Could it be with Views?
Any pointers appreciated - I'm moving & learning from Access to SQL
View 4 Replies
View Related
May 19, 2005
Hi,
I have small question regarding ORDER BY clause.
I wanted some value of the fields should come first before other values….Something like:
+----------+----------------------------------------+
| code | name |
+----------+----------------------------------------+
| UK | United Kingdom |
| US | United States |
| AF | Afghanistan |
| AL | Albania |
| DZ | Algeria |
| AS | American Samoa |
I want to display country UK and US code first and then rest of the countries using SQL statement. I know in MySQL, I can use ORDER BY code IN (...)
--SQL
SELECT * FROM countries ORDER by code IN ('UK', 'US') desc
But not sure how can I do same thing in SQL Server. Is there any equivalent of ORDER BY [field] IN (…) clause in SQL Server???
Though I can create a new field something like sequence and use it to display these countries but I can not do that…
Please advice.
Thanks,
Firoz Ansari
View 1 Replies
View Related
Jan 15, 2001
Is there an equivalent to Oracle's ROWNUM in SQL Server. ROWNUM, when added to a select statement as a column - the query would return an automatic counter, numbering each row returned.
View 1 Replies
View Related
Apr 22, 2003
Hi,
Is there something equivalent to the MINUS in ORacle ?
Or a workaround ?
thanks
View 11 Replies
View Related
Sep 7, 2005
There are three columns I need to query and rank, then group and total. I'm using MS SQL server 2000 and it doesn’t have a ranking function like the newer SQL server and oracle has. Does anyone have a clever way to create or simulate a ranking function? Thanks so much!
Jake :confused:
View 1 Replies
View Related
Jan 9, 2002
I'm trying to get a tree structure from a table. Ex : Security table.
How can I accomplish that task in SQL Server?? I will do it using Level and connect by operators in Oracle to accomplish the task.
Your reply in this regard is highly appreciated.
Thanks,
Navy
View 1 Replies
View Related
Jul 9, 2004
I have a SQL Server database which has one user (UserA) which owns some tables. I've added an additional user (UserB) to the database such that it has access to the tables owned by UserA. What is happening is that when I log on as UserB I have to fully qualify table names and fields in my SQL statements when I deal with tables owned by UserA. Is there a way make the tables accessible without specifying the owner? In Oracle you could create a public synonym for the table eg. <table_name>. Wherever that synonym is referenced the DBMS would know thats its refering to UserA.<table_name>. Is such functionality available in SQL Server? Thanks.
View 2 Replies
View Related
Sep 2, 2004
Hi,
Can any one tell me is there anything in SQL Server thats equivalent
to Oracle's ROWNUM.
Note that the Identity Property or TOP n will not solve my problem.
I want to asign a sequence no. to each row when its being fetched.
For example if in the emp table there are 2000 rows and I write
the following query in Oracle ,
SELECT rownum , empno, empname FROM emp Where rownum < =3
I get the result like this
Rownum----Empno--------------Empname
------------------------------------------
1-----------2345---------------ABCD
2-----------3334---------------EFGH
3-----------4484---------------IJKL
I know I can limit the output rows in SQL Server by using TOP n. But
I also want to generate a sequence no. The identity property of SQL Server
will not be usefull here because my actaul WHERE clause will be more
complex like WHERE resigndate = '01-jan-2004'
Thanks
Asim Naveed
3
View 2 Replies
View Related
Jan 19, 2007
Hello Guys!i have been working with oracle with quite a time. No i migrated to sqlserver 2000 and i want to create a trigger on a table.the trigger function has to update the Modification field to getdate()whenever a row is being updated.i tried lots of thingsif anyone can help i would appreciate a lot!Regards
View 2 Replies
View Related