Extracting A Portion Of A String In SQL Server 2005

Apr 22, 2008

Hello, this seems simple but I've been banging my head a while.

I have a data field that is formated like this: NYT/2000-Subways/7510-Electronics Mtc/7540-Data Svcs.

I need to pull out the string after the second / and before the third / in this case the value is 7510-Electronics Mtc but it does change.

I have this function that returns the first value (NYT):

USE [Data_Warehouse]
GO
/****** Object: UserDefinedFunction [dbo].[Get_Dept] Script Date: 04/22/2008 09:22:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- Provide the phrase before (ex. 'Worklog Related to'), the field searched (ex. UPDATE_ACTION), and
-- the phrase after (ex. ']').
-- This function returns the string found after any phrase and before any phrase, within any field searched.

ALTER FUNCTION [dbo].[Get_Dept](@in_Phrase_Before varchar(250),@in_Search_Field varchar(250))
RETURNS varchar(250)
AS
BEGIN
Declare @str_String As varchar(250)
Declare @tmp_String as varchar(250)
Set @str_String = null -- to clear the variable buffer

Set @in_Phrase_Before=char(37)+(LTrim(Rtrim(@in_Phrase_Before)))+char(37) -- if 'Null', all strings will be returned

If Left(@in_Search_Field,4) = 'NYT/'
BEGIN
Set @tmp_String = Right(@in_Search_Field,(len(@in_Search_Field) - 4 ) )
Set @in_Search_Field = @tmp_String
END

If (PatIndex(@in_Phrase_Before, @in_Search_Field)) > 0 --Checks to see if the phrase before is in the search field
Set @str_String=SubString(@in_Search_Field,1, (PatIndex(@in_Phrase_Before, @in_Search_Field)-1) )

RETURN @str_String

END

Thanks in advance for the help

View 10 Replies


ADVERTISEMENT

Extracting A Portion Of PK Data

Mar 27, 2008

I want to extract a particular portion of primary key field data.For example- suppose there are fifty data in PK field starting from 1...50.Now I want only to extract data from 25 to 50.It is bcos I want to retrieve only the new data that is inserted after a specified time.For example-today there is data starting from 1 to 25 which I have retrieved and saved elsewhere.By tomorrow there will be new data starting from 26 to 50 or more.Now I just want to extract this additional data from the database so that I dont need to extract all data again.Could anybody pls tell me how to do this.How can I do it using common SQL bcos I have to make a program for it.

View 1 Replies View Related

SQL Server 2012 :: Extracting String Between Certain Characters

Aug 18, 2014

I need extracting string that is between certain characters that are in certain position.

Here is the DDL:

DROP TABLE [dbo].[StoreNumberTest]
CREATE TABLE [dbo].[StoreNumberTest](
[StoreNumber] [varchar](50) NULL,
[StoreNumberParsed] [varchar](50) NULL)
INSERT INTO [dbo].[StoreNumberTest]

[Code] ....

What I need to accomplish is to extract the string that is between the third and fifth '-' (dash) and insert it into the StoreNumberParsed while eliminating the fourth dash.

Sample output would be:

KY117
CA132
OH174
MD163
FL191

I know that parse, charindex, patindex all might come in play, but not sure how to construct the statement.

View 5 Replies View Related

SQL Server 2008 :: Extracting Numbers From String

Jun 2, 2015

Anyny in-built sql function that gives us numeric values in a string?

I have to deal with some inconsistent US phone numbers stored in DB. They are stored as

(xxx)xxx-xxxx
xxx xxxx xxxx
(xxx) xxx-xxxx
xxx-xxx-xxxx
xxxxxxxxxx

I don't want to apply nested REPLACE function to eliminate all unnecessary characters to get 10 digit number from DB.

View 9 Replies View Related

T-SQL (SS2K8) :: Returning Only Portion Of String?

Jun 19, 2014

i need to cut my string on 3 portion, for exemple my string is :

a) 1.9999-Q1

b) 01.9999-Q11

I need to keep all values before "." (point), and all values after "-" , and also all values between "." and "-", like this:

a) 1
9999
Q1

b) 01
9999
Q11

View 9 Replies View Related

Replacing A Portion Of Text String In Column

Jul 20, 2005

I need to replace a portion of a url in a column as a result ofchanging servers. Is there a SELECT/REPLACE/UPDATE combination querythat can do this. The table has close to a thousand entries and wouldbe nice if a query can be set to do this. Tried the REPLACE examplein the BOOKS ONLINE but it creates syntax error, apparently because itdoes not like the characters in the url and/or wildcards. I don't needto replace the entire url, only the portion before ".com". Thanks inanticipation of your help.Pradip Sagdeo

View 3 Replies View Related

Extracting The Oracle Data Into SQL Server 2005.

Apr 28, 2008

Hi All,

We are extracting the data from ORACLE databse into SQL Server 2005 database. Both are hosted on different servers.

For this we have created linked server on SQL Server and we using the OPENQUERY to extract the data. Its taking too much time to extract the data.

Is there any other alternate thing for OPENQUERY clause.

Please help me on this.

Thanks in advance.

Thanks,
Ramesh.

View 3 Replies View Related

Extracting Part Of A String

Aug 22, 2006

Hello,

I have a field in my table that includes free form text. Within this text are two five digit numbers seperated by a forward slash (/). I need to be able to locate the "/" and then return and display the numbers before and after the "/" seperately. For example:

"the text looks like this but has two numbers 55555/66666 within the string"

I need to get the "55555" and the "66666" in oprder to then display them. can anyone help? I am using ASP/SQL. Appreciated in advance!

View 5 Replies View Related

Transact SQL :: Extracting A Word From String?

Jun 30, 2015

Is there a function / way to extract a word from a particular position in the String.

I want to extract a word which is in the 16th position. All words are separated by spaces.

View 6 Replies View Related

EXTRACTING DATA FROM FOXPRO/ACCESS 2000 INT SQL SERVER 2005

Mar 5, 2007

Dear Sir/Madam,

I have some data which is stores in Foxpro dbf files & Access 200 MDB file. Can i extract import these files into SQL Server 2005



View 3 Replies View Related

Extracting MS Excel Data In MSSQL Server 2005 Express

Aug 26, 2006

Is there a way of extracting data from MS Excel using MS SQL Server 2005 Express?

View 1 Replies View Related

Installing Sql Server 2005 Trial Software From Microsoft Website - Self Extracting Executable

Nov 14, 2005

Hello,

View 1 Replies View Related

Extracting PDF's Into My SSRS 2005 Report

Nov 19, 2007

We are currently designing a report which we hope is possible. Each month the clients employees upload receipts as PDF's to the network and then fills out their form as needed.

We are planning to upload the PDF's to a Microsoft Office 2007 sharepoint site which we would like to then pull out and use as being part of the report.

So page one will be a list of expenses pulled from a database table and the remaining pages will then be the PDF's showing as part of the report. I have seen the Jump to URL option but that presents a hyperlink option only. I need to see the actual pdf in the report.


Has anyone done anything similar where they have extract a PDF to show in a SSRS 2005 report

Many thanks

View 1 Replies View Related

SQL Server 2005 Connection String In Visual Studio 2005

Nov 14, 2006

Hey
I need to know what shall i specify in this connection string in visual studio web.confug file inorder to connect to ma registered server (locally) not directly to my dedicated server ....cuz i am facing network connection problems ....
b4 i used to use this connection string :
<add key="conn" value="data source=IP addresseel,1433;initial catalog=xxx;user id=username on the dedicated server;Password=password on the dedicated server;timeout=60"></add>
So how can i change it ???? to be able to connect locally ????
Please Help ???!
Thanks in advance
Hiba

View 13 Replies View Related

Extracting DDL's In SQL Server

Sep 17, 2004

I really apprciate any idea's

On extracting ddl's for each object on a separate file in SQL Server?

Something like ddl's for:
procedure1.sql, procedure2.sql.....so on procedure100.sql
onto a file server.

Does SQL Server has any API's like Oracle's dbms_metadata?

Or can we use SQL enterprise manager to do this job?

Thanks, Madhavi.

View 3 Replies View Related

String Concatination From XML In SQL Server 2005

Jul 17, 2006

I have a stored procedure where I want to loop through the nodes of an XML type and use its values to perform string concatination.
I'm new to the XML type in SQL Server and to XQuery in T-SQL and am wondering if someone can point me in the right direction. The XML samples I've found so far focuses on returning a set of nodes or building XML to store, not reading it in T-SQL and building strings.

View 1 Replies View Related

Extracting Data From Sql Server 6.5

Jan 22, 2008

Hi!

I'm analyzing the problem of extracting data from sql server 6.5 in order to load it into oracle.

I already know about the bcp tool, but I'd like to know if you would consider any other approach based on SSIS, or any other tool like SQL Load.

regards, and thanks in advance for your help.

View 1 Replies View Related

Microsoft SQL Server 2005, Connection String

Jul 27, 2006

<connectionStrings>
<add name="AppConnectionString1" connectionString="Data Source=&quot;.SQLEXPRESS&quot;;AttachDbFilename=&quot;C:Program FilesMicrosoft SQL ServerMSSQLDataAdventureWorks2000_Data.mdf&quot;;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I'm running Microsoft SQL server 2005. what is the error in the above code.

View 2 Replies View Related

SQL Server 2005 Enterprise Connection String.

Jan 2, 2007

Hi,
I have just uninstalled SQLEXPRESS and installed the 180 day trial SQL server 2005 enterprise edition.
I have since started to have problems with my ASP.Net Configuration Tool., can not connect to the database.
I think that the connection string in my machine.config file is incorrect, before installing I had,..:
datasource=./SQLEXPRESS,....
So i decided to change that part to the following. Would anybody know what I have put in the datasource part for the SQL server 2005 enterprise edition? At the moment I tried SQLSERVER2005 but that is incorrect,..
<add name="LocalSqlServer" connectionString="data source=./SQLSERVER2005;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
 

View 1 Replies View Related

Connection String For Sql Server 2005 Express

Jan 10, 2008

does anyone kbnow the connection string used to connect to the database in sql server 2005 express?
can someone one give me sample codes for it? thanks.


thanks

View 1 Replies View Related

Connection String Question - SQL Server 2005

Mar 12, 2007

What is the impact of the differences in the following 2 connection strings:

Initial Catalog=xxx;Data Source=xxxxxx;Trusted_Connection=True;

Driver={SQL Server};Server=xxxxx;database=xxx;Trusted_Connection=yes;

To outline the differences I'm concerned with are


Missing Driver on first string

Difference in Trusted_Connection parameter (true vs. yes)

Initial Catalog vs. database parameter

View 6 Replies View Related

Extracting Data From Exchange Into SQL Server Db

Mar 22, 2002

Has anyone been able to solve the issue with setting up a package in EM, which connects to an Exchange(.edb) database and extracts the data into a SQL Server db. Previous message posts don't offer much insight. So far, all I have is using Access 2000, to connect & move the data, then extract from here.
Thanks in advance for any help.
BV

View 1 Replies View Related

Extracting Duplicates From SQL Server 2000

Dec 28, 2007

Hey Guys,Total Number of Records (Based on 5 fields): 1000Total Unique Records (Based on 5 Fields): 990Total number of fields: 5I have question regarding extracting duplicates from the dataset. Ihave 2 fields that makes a record unique. I have used group byfunction to find duplicates and got 10 records that are duplicating.Each records duplicating 1 times, thus, 10 unique records and 10duplicates, giving me 990 unique records out of 1000.Now, I want to filter out duplicates from the dataset and get uniquerecords, including all 5 fields. Here is the query that I used.select *from (select field1, field2, count(*)from table 1group by field 1, field2having count(*) >1)a,table 1 bwhere a.field1=b.field1 and a.field2=b.field2When I use this query, it gives me duplicate records as i am matchingon both fields that makes records unique. Is there anyway to justextract unique records?Thank you very much for your help.--AP

View 4 Replies View Related

Extracting Data From LotusNotes Into SQL SERVER

Feb 15, 2007

I have a form in Notes that is huge. I need to extract a part/field from that form into SQL SERVER. If I use NotesSQL Thru SQL DTSPackages, I am afraid it will run very long. Is there any other option on that?

Any help is appreciated.

View 2 Replies View Related

Connection String To SQL Server 2005 Express Database

Apr 10, 2008

Hi, all. I am using VS.NET 2005 and SQL Server 2005 Express. I tried to use the following code to connect to a database named "AMSPROD" that I attached to SQL Server 2005 Express:
 dbConn = new OleDbConnection(Data Source=.SQLEXPRESS;AttachDbFilename="C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDataAMSPROD_Data.MDF";Integrated Security=True;Connect Timeout=30;User Instance=True);
dbConn.Open();
I got an error asking for provider with the above connection string, then I changed the conncection string to be like follows:
Data Source=.SQLEXPRESS;AttachDbFilename="C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDataAMSPROD_Data.MDF";Provider=SQLNCLI;Integrated Security=True;Connect Timeout=30;User Instance=True
I got error: No error message available, result code: DB_E_ERRORSOCCURRED(0x80040E21)
Then I changed the Provider to be like: Provider=SQLOLEDB, now I am getting the following error:
Message: "Invalid authorization specification
Invalid connection string attribute"
Source: "Microsoft SQL Native Client"
StackTrace: " at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at ISESAMSData.DbConnections.MakeConnection() in C:\ISES\ISESCommon\ISESAMSData\DbConnections.cs:line 74"
TargetSite: {Void .ctor(System.Data.OleDb.OleDbConnectionString, System.Data.OleDb.OleDbConnection)}
Strange thing is, when I use the Connect To Database under Tool menu of VS.NET 2005, I could make the connection to this database. Then I copied this connection string to the code, the connection couln't be made. I feel very confused.
I am wondering if I need to add ASP.NET user to SQLExpress. But I don't know how to do it?
Can anyone please help me out! Many thanks!

View 7 Replies View Related

SQL Server 2005 Express Edition Connection String (dns-less)

Jun 12, 2006

Junifer writes "Hello guys,

Can you give me a simple example of a dns-less connection to SQL Server 2005 Express Edition?



Thanks."

View 1 Replies View Related

Connection String For Classic ASP Global.asa To SQL Server 2005

Dec 1, 2005

I migrated my SQL Server 7 database to the new SQL Server 2005 that I installed on my PC.  I have classic ASP programs on my PC that used to access the SQL Server 7 database.  However, global.asa and these ASP programs can no longer connect to the new SS 2005 database.

View 9 Replies View Related

SQL Express 2005 Connection String Vs SQL Server (latest)

Oct 28, 2007

I'm a student at Boise State university and we're using SQL Express as part of one of our projects for ASP.NET programming. I liked it and I'm trying to use it to power a wiki that I'll be hosting from my home internet connection. The wiki is compatible with MSSQL server, but it won't connect to SQL Express.

I suspect that the problem is in the connection string, mainly because the apps we're developing for class use a connection string like:
<add name="AspNetForumConnectionString" connectionString="Data Source=localhostsqlexpress;Initial Catalog=gaming.forum.nxnw;User ID=*********;Password=*********;" providerName="System.Data.SqlClient"/>

and note the Data Source. The wiki I'm using is PHP based and uses ADObd to connect databases and has a driver for MSSQL, but not SQL Express (no surprise, really). I know just enough php to be dangerous to code and I've tried modifying the adodb-mssql.inc.php, but I can't seem to make the right change.

So, all that said, my question is: Is there a way to change what SQL Express 2005 will accept as a connection string? I've been looking, but I'm not even sure what the setting would be called.

Thanks,
Les

View 6 Replies View Related

SQL Server 2008 :: Extracting Data From Linked Server

Dec 17, 2010

I am using MS SQL 2008, and I am trying to extract data from a MySQL database. I am having trouble extracting the data I need.

In SQL Server management studio, I can see the linked server...I can browse the different databases on the server. I can see user and system tables in all of the databases.

When I try and query a linked table (select * from server.db.table) I get Invalid object name 'servername.databasename.tablename'.

When I try script the table.. right_click on the linked table, Script table as, Select to, New Query Editor window, I get an error '[servername].[databasename]..[tablename] contains no columns that can be selected or the current user does not have permissions on that object.'

This leads me to believe that it is a permissions problem, but if I have access to the MySQL database using MySQL and the same login/password) and can retrieve the data there, then I think my login credentials should be enough using MS SQL. I guess I think its odd that I could have enough credentials to get in and see table names, but not do a select against it.

View 8 Replies View Related

Extracting Binary Data From SQL DB To A Location On The Web Server

Mar 15, 2007

Hey all, WE have a document management system where by Adminstrators can upload documents, once the document is uploaded the binary data is stored on in a folder on the web server.  We used to stored the documents in the actaul db table, but we found that there were to many documents and it was using alot of space on db server. So my boss has decided we are now going to upload the binary data onto the web server.  Currently we are donig this with new documents which have been added or documents which are gettinguploaded when reloading, but there are many documents in the db table which have not been updated and are still embedded in the db table.  So i need to figure out how to go about copying the data storewd in the db table and storing it in web servers folder location. I've tried various things for a enitre day but im going round in circiles.                             MemoryStream mStream = new MemoryStream((Byte[])dtrResults["file"]);                            BinaryReader bReader = new BinaryReader(mStream);                            int intFileSize = (int)mStream.Length;                            Byte[] byteFile = (Byte[])dtrResults["file"]; i can get to this state but then how do i create a folder on the BinaryREader to then store the binary data of the file to the location.                             BinaryReader bReader2 = new BinaryReader(File.Open(strDocFolder + strSavedFileName, FileMode.Create));                            int count2 = bReader2.Read(byteFile, 0, intFileSize);                            bReader2.Close();i've also tried this but when the file gets created in the folder there is no content.  i do know that the file does contain content as ive tried this and downlaoding the file from that page acctually works                            string strContentTpe = WValue.WStr(dtrResults["contenttype"]);                            int intFileSize = VValue.VInt(dtrResults["filesize"]);                       /    Byte[] byteFile = ((Byte[])dtrResults["file"]);                            //Downloads the data correctly                           Response.ClearContent();                          Response.ClearHeaders();                           Response.AddHeader("Content-Disposition", "attachment; filename="" + WValue.WStr(dtrResults["docfilename"]) + """);                           Response.AddHeader("Content-Length", WValue.WStr(intFileSize));                          Response.ContentType = strContentTpe;                           Response.BinaryWrite(byteFile); I hope ive made some snese andthat someone can hlep me. Have a nice dayZal     

View 2 Replies View Related

Extracting Data From Oracle Into SQL Server 6.5/Sybase

Feb 7, 2001

I have a coworker who needs to extract data from Oracle into SQL Server 6.5 and Sybase as part of an interface that runs daily. How is the best way to do this?

Tony

View 1 Replies View Related

SQL Server 2012 :: Extracting Data From XML Query

Sep 28, 2015

I'm trying to extract some data from an XML column, into the demo below I would like to obtain the CommandText value but my attempts so far are in vain, I'm fairly sure its just a path issue in the .query command but I just can't seem to get it to work.

create table #demo (field1 xml)
insert into #demo (field1)
values ('<SharedDataSet xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/shareddatasetdefinition">
<DataSet Name="DataSet1">

[Code] ....

View 6 Replies View Related

SQL Server 2014 :: Extracting Data From Database?

Nov 5, 2015

I am running an hotel application for all the bookings.

I would like to get all the data of all the guests that stayed in the hotel (name, stay duration and dates, payment, etc).However, the GUI would make me go over one booking at a time, which would take me forever.

The application has an SQL database locally on my computer.

Will I be able to use SQL server and extract all the guests data from the last year and export it into a file, e.g. A CSV file?

View 8 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved