Pulling Out PO# From The Rest Of The Job Descrip.

Apr 29, 2008

Hello, I am new here and to sql so please bare with me.

I am trying to create 2 select statements from the same field. The field is a job_description field that sometimes contains PO#'s. One select statement needs to extract the PO# if it has been written in the field and the other needs to extract all data that is not the PO#


Here is some example of the data:


New shirts for 2007
Magazine cover for may edition
Way to go postcards PO# 45687
PO#879


For the first select statement I need to capture just the PO#. the result for the above examples would be:

NULL
NULL
45687
879

For the second select statement I need everything but the PO#. The result would be:

New shirts for 2007
Magazine cover for may edition
Way to go postcards
NULL

So far I have put together a basic idea for the PO# part:

(SELECT SUBSTRING (job_description , (SELECT patindex('%PO#%', job_description)+3),10)WHERE job_description LIKE '%po#%')

If i could figure out a way to only return numeric data from the above i think it will work.

As for the second select statement i am at a loss on how to select everything but the PO#.

Any help at all is very much appreciated.

Thanks

View 2 Replies


ADVERTISEMENT

SQL: How To Display Top 5 Then Sum The Rest

Apr 6, 2006

Hello,I would like to query the top 5 best companies' sales (total sales),then total the rest, what is the quickest and effective SQL to queryit?Thanks in advance

View 8 Replies View Related

Analysis :: TOP N Plus Rest

Nov 17, 2015

I need to create a dynamic top count of customers, plus the rest. I've seen many posts on this, however the difference I want is that the rest needs to be expandable to show what customers actually make up the rest category. For example:

Top

Cust1
Cust5
Cust2
Rest
Cust3
Cust4

I was thinking potentially the top/rest could be a shell dimension and then scope on these members to show the top and rest, however I haven't been able to achieve this.

View 5 Replies View Related

How Can I Keep Only The Top Ten Rows And Delete The Rest

Dec 17, 2007

I have a table that I would like to only keep the top 10 rows for each username. How can I kep the top 10 and delete the rest?

View 17 Replies View Related

Rest Primary Keys?

Mar 20, 2008

HiI have a database and I been inserting some dummy data into it but now I want to upload it to my website but I want to delete all the dummy data and start the PK back at 1. I truancted all the data but it still keeps counting from the last one.So how do I reset it? 

View 6 Replies View Related

T-SQL (SS2K8) :: How To Return Top N And Sum Up The Rest

Feb 10, 2015

I am looking for an elegant way to return top n and sum up the rest, in my case CTE/temp table/variables are not allowed.

View 9 Replies View Related

If One Of The BCP Fail. Does It Affect The Rest Of The Process??

Dec 8, 1998

Hi, I am wrote the following code in one store procedure called p_bcp_all.
and then scheduled it to run over night. what if the first two bcp were successful but the third one failed. Is the whole procedure going to fail? also what if the first one failed, is the rest of the code going to be executed have the bcp process going for the second and the third table?
thanks for your adivce

regards Ali

create procedure p_bcp_all as
Exec master..xp_cmdshell "bcp servername..tblone in d:blone.txt /fd:formatfileblone.fmt /servername /Usa /password/b250000 /a8000"

Exec master..xp_cmdshell "bcp servername..tbltwo in d:bltwo.txt /fd:formatfilebltwo.fmt /servername /Usa /password/b250000 /a8000"

Exec master..xp_cmdshell "bcp servername..tblthree in d:blone.txt /fd:formatfileblthree .fmt /servername /Usa /password/b250000 /a8000"
GO

View 2 Replies View Related

Capitalizing First Letter, And Lower The Rest

Oct 25, 2006

I am trying to get this code to work: (left(religion,1))+ lower(right(religion,len(religion)-1))As Religion

I am getting this error:

Invalid length parameter passed to the RIGHT function.

View 6 Replies View Related

With User Sa I Can See Mot Databases How Can The Rest Of The Users See Them All?

Jun 26, 2007

I have a third party application that creates several databases on my sql server. This party uses the same user for accessing all this databases. However after moving to a new server this databases the user is no longer able to query them whith the exception of the "sa" user. Could anyone explain me how to add permissions to this databases manually so the user can query them again.

Thanks in advance

brgds

Miguel

View 3 Replies View Related

T-SQL (SS2K8) :: Take ID Value From Maximum ID And Compare Rest ID Value From Table

Jul 2, 2014

--drop table #temp
create table #temp (id int, idvalue int)
insert into #temp(id,idvalue)
select 1095,75

[code]...

I need to take the id value from maximum's id, and compare the rest id value from the table. i need to check the diffrence , if diffrence is more than 18, then i need to raise the flag as failure otherwise the whole test is success. i need to take 63 and compare rest 69,65,61,75.check the diffrence less than 18 or not.

View 3 Replies View Related

Retaining Records Of Top N Rows And Deleting The Rest

May 15, 2008

Hi All,
I am writing a SP where I need to pass an value to maintain records of last n days. In this SP I am deleting a couple of tables based on the value passed to this SP. For e.g. If the SP is passed the value 10, then only TOP 10 records is maintained, the rest are deleted.
I have formed the following logic, which I feel can be improved vastly.
I create a temp table and

CREATE TABLE #TempAuditTbl (Rownum int PRIMARY KEY, Orderid uniqueidentifier)

INSERT INTO #TempAuditTbl

SELECT ROW_NUMBER() OVER (ORDER BY orderdate desc) AS rownum, Orderid FROM Orders

DELETE Orders FROM Orders INNER JOIN #TempAuditTbl adt ON adt.Orderid = Orders.Orderid AND rownum > @TopnRows

DROP TABLE #TempAuditTbl


OR


DELETE FROM Orders WHERE orderid NOT IN ( SELECT TOP @TopnRows OrderID FROM Orders ORDER BY OrderDate desc)

This way I am able to keep the top n records.
Which of these two solutions is more efficient? Is there a more efficient way to achieve the same.
Please help.

Thanks & regards
Sunil

View 13 Replies View Related

Delete/Move Certain Info From Column - Leave The Rest?

Nov 10, 2005

I have a column that contains extra info that needs to be moved to another column or deleted alltogether. is there a way to select these items and move them to another column, leaving the rest of the data in the original column?

EXAMPLE

MYTABLE >COLUMN1
May have Data Like: ABCDE123 SER1 or XYZ12DEFSer1:1

WHAT I NEED TO DO IS
Move anything after the SER1 to a new column and retain the rest of the data in the original column. making it look something like this:

COL1 COL2
ABCDE123 SER1
XYZ12DEF Ser1:1

Another question is if there is a way to delete extra spaces? Like make all data that has two or more extra spaces, just single spaces and any additional spacing after a row of data, delete all additional spaces after the last letter/character/number.

One more question - What would be a great resource to learn MS SQL in more depth?

I am trying to learn ASP/VBScript/JavaScript/ and now MS SQL all at once b/c this is what my business depends on. Trying to be 5,000 hats at once can get confusing and overwhelming, so I am looking for any "Crash course" I can to learn as much, as fast as possible. Any direction or ideas?

Thank you.

View 4 Replies View Related

How To Commit The Rest Of The Transactions Of An Update In Large Bulk?

Feb 8, 2004

I have to modify the table structure where the table have a lot of data already. The log is getting full due to uncommitted transactions, there is a lot of data being updated in large bulks, not all of the transactions are committed, the update task cannot be completed.
However, there is no more spare disk space for it to commit the transaction. Anyone can help?

View 2 Replies View Related

Display Data First Letter Uppercase Rest Lowercase

Sep 19, 2006

I know you are able to display data all uppercase or all lowercase, but how do you display it First letter capital rest lower. Like a First or Last name?

View 3 Replies View Related

Friendly Way To Look At Sqlagent Ssis Messages Without Exporting Rest Of Log

Apr 13, 2008

I just started playing with sqlagent and am finding that viewing a specific message from an ssis step is cumbersome when other entries are also in the log. Exporting seems only able to export all history entries. Viewing right in the log viewer leads to a series of boundary expansions and right scrolls that dont seem convenient for quick identification of a problem in a medium sized ssis message. Right clicking on the message in the viewer seems like it is preparing the message for possible copy but it seems to end there. I'm already familiar with the different levels of verbosity available in the command line. Dont see anything useful on the web.

Is there a user friendly way to copy the contents of a specific message for perhaps pasting to notepad , so that problem identification is facilitated? Is there a not so user friendly way available, one taht doest involve 1st exporting the entire log?

View 7 Replies View Related

SQL Server 2008 :: Using Left And Charindex To Parse String / Getting Rid Of Rest Of Data

Jun 16, 2015

I am trying to erase some erroneous bad data in my table. The description column has a lot of </div>oqwiroiweuru</a> weird data attached to it, i want to keep the data to the left of where the </div> erroneous data begins

update MyTable
set Description = LEFT(Description(CHARINDEX('<',Description)-1)) where myid = 1

that totally works.

update MyTable
set Description = LEFT(Description(CHARINDEX('<',Description)-1)) where myid >= 2

gives me a Invalid length parameter passed to the LEFT or SUBSTRING function. The statement has been terminated error.

View 2 Replies View Related

Reporting Services :: Expression To Change All Caps To First Letter Uppercase And Rest Lowercase

Aug 1, 2015

The states in this report are all in caps TEXAS, CALIFORNIA, etc.. Is there a way to use expressions to only have the first letter in uppercase and rest in lowercase?

View 3 Replies View Related

SQL Server 2008 :: Update Null Enabled Field Without Interfering With Rest Of INSERT / UPDATE

Apr 16, 2015

If I have a table with 1 or more Nullable fields and I want to make sure that when an INSERT or UPDATE occurs and one or more of these fields are left to NULL either explicitly or implicitly is there I can set these to non-null values without interfering with the INSERT or UPDATE in as far as the other fields in the table?

EXAMPLE:

CREATE TABLE dbo.MYTABLE(
ID NUMERIC(18,0) IDENTITY(1,1) NOT NULL,
FirstName VARCHAR(50) NULL,
LastName VARCHAR(50) NULL,

[Code] ....

If an INSERT looks like any of the following what can I do to change the NULL being assigned to DateAdded to a real date, preferable the value of GetDate() at the time of the insert? I've heard of INSTEAD of Triggers but I'm not trying tto over rise the entire INSERT or update just the on (maybe 2) fields that are being left as null or explicitly set to null. The same would apply for any UPDATE where DateModified is not specified or explicitly set to NULL. I would want to change it so that DateModified is not null on any UPDATE.

INSERT INTO dbo.MYTABLE( FirstName, LastName, DateAdded)
VALUES('John','Smith',NULL)

INSERT INTO dbo.MYTABLE( FirstName, LastName)
VALUES('John','Smith')

INSERT INTO dbo.MYTABLE( FirstName, LastName, DateAdded)
SELECT FirstName, LastName, NULL
FROM MYOTHERTABLE

View 9 Replies View Related

I Really Need Some Help, Im Pulling My Fingers Off...

Mar 16, 2006

Ok, to start, i have read SO many posts on this site, and othe sites, and i cannot get this to work.

What i want to do is:
1. Login
2. show an image from a SQL database, based on that login.

I have the image path stored in the database, and i can easily get it
to display on the screen, but it doesnt show the correct image for the
login, it shows them all. (all images based on that column).

I know i have to put a WHERE at the end of my SELECT statement, but everything i have tried doesnt work.

When i do the query builder, and i put in the value, it shows exactly what i want, based on the login's username.

I know i am close, i just can't finish it.


Please help.

Thanks

View 4 Replies View Related

Pulling My Hair Out...PLEASE Help

Aug 1, 2006

Ok so every week I have to download a file containing in excess of 40000 products. I then have to change the category ids to suit my system. Is there a script or something that I could create so I just run it each week to do a search and replace and then loop until all category ids have been changed.

Table = ecommstore
Column = section

I would need to change say from 84 to 1 then 86 to 2, 87 to 3 etc etc

View 12 Replies View Related

Pulling Up A Link

Feb 21, 2008



I have had an unusual request and I thought to ask youreal smart folks out there for a hand.
I am working with a non microsoft application that writes links to an html file. I need to extrapolate the link and pull it into a database table on our MS-SQL 2005 server.
I believe that this woould best be done with a stored procedure.

I guess that I will get the files and save them on a given directory on the W2K3 Enterprise server and run the proceedure there.

All comments are welcome.
Thanks in advance,
Gene

View 6 Replies View Related

Pulling HTML Out Of A Database

Jul 9, 2007

Good Morning,
I'm not quite sure this is the right place to post this, but i'll try anyway.
I have a website where I allow people to create their own layouts in HTML, and in the HTML I have them placeing markers (eg. |1| ) where they would like to place something from a database. All the HTML is stored in a SQL Server DB, and when I pull it out, it's fine, except it won't allow me to Replace any of the markers with values from the DB.
Here's and example line of HTML that's held in the DB:<table width='50%' border='1'><tr><td>|0|</td><td>|1|</td></tr>
 and when I do a strHtml.Replace("|0|", dReader["somefield"].ToString()) or even just a strHtml.Replace("|0|", "Test") it never changes it.
Anyone have any ideas?
Thanks,
Deepthought

View 1 Replies View Related

Pulling Values From Code Behind

Jul 18, 2007

In my code behind file I have this function:
 1 public void getAllSystems()
2 {
3 MTConnection con = MTConnection.CreateConnection(new Credential(new Context("ClearQuest - Boise", "Version 2.0", Micron.Application.Context.Environments.Production), "DSSPROD", Credential.DataSourceTypes.MSSQL, Credential.DataSourceProviders.Odbc));
4
5 string sqltest = " select T1.dbid,T12.systemname AS 'ParentSystem',T1.systemname AS 'SupportSystem',T1.systemstate,T1.features,T3.name,T4.stakeholder," +
6 " T4.fldcolumn_1,T1.systemwebpage,T1.description from ( ( ( ( ( ( ( ( CQ_ADMIN.micronsystem T1 INNER JOIN" +
7 " CQ_ADMIN.microngroup T6 ON T1.primarysupportgroup = T6.dbid ) INNER JOIN CQ_ADMIN.securitygroups T7 ON T1.secuirtygroup" +
8 " = T7.dbid ) LEFT OUTER JOIN CQ_ADMIN.parent_child_links T12mm ON T1.dbid = T12mm.child_dbid and 16778862 =" +
9 " T12mm.child_fielddef_id ) LEFT OUTER JOIN CQ_ADMIN.micronsystem T12 ON T12mm.parent_dbid = T12.dbid )" +
10 " LEFT OUTER JOIN CQ_ADMIN.parent_child_links T3mm ON T1.dbid = T3mm.parent_dbid and 16804095 =" +
11 " T3mm.parent_fielddef_id ) LEFT OUTER JOIN CQ_ADMIN.feature_1 T3 ON T3mm.child_dbid = T3.dbid ) LEFT OUTER" +
12 " JOIN CQ_ADMIN.parent_child_links T4mm ON T3.dbid = T4mm.parent_dbid and 16804263 = T4mm.parent_fielddef_id )" +
13 " LEFT OUTER JOIN CQ_ADMIN.stakeholder T4 ON T4mm.child_dbid = T4.dbid ) where T1.dbid <> 0 and ((T6.abbreviation =" +
14 " 'Test ES Eng Software' and T1.systemstate = 'Active')) and ((T7.dbid in (select parent_dbid from" +
15 " CQ_ADMIN.parent_child_links where parent_fielddef_id = 16778767 and child_dbid in (select child_dbid from" +
16 " CQ_ADMIN.parent_child_links where parent_fielddef_id = 16777328 and parent_dbid = 33664106)and T12.systemname IS NOT" +
17 " NULL ))) order by T3.name ASC,T1.systemname ASC";
18
19 System.Data.DataSet ds = con.ExecuteDataset(CommandType.Text, sqltest);
20
21 foreach (DataRow drCQ in ds.Tables[0].Rows)
22 {
23 string parent_system = drCQ["ParentSystem"].ToString();
24 string child_system = drCQ["SupportSystem"].ToString();
25 //Response.Write(child_system + "<B><I>'S PARENT IS</I></B> " + parent_system + "<BR />");
26 }
27 }
I would like to pull the values of parent_system and child_system into my main page but I don't know how to do that. Is it even possible?Thanks,Xana.
 

View 13 Replies View Related

Pulling Single Lines From A DB

Apr 26, 2004

hi im making a page where i want a single line at a time to be pulled from my MS Database, basically at the moment i have a list of questions, but the page is displaying all the questions from my database, i only want it to pull out 1 and then if the user clicks the true button then it goes to another page and displays another question?

Any ideas

Regards,

Joe

View 1 Replies View Related

Pulling Information From Exchange Into SQL?

Apr 3, 2001

I am looking for something on pulling information from Exchange 5.5 Sp4 to SQL7.0. Anyone know where I can start?
-Stu

View 3 Replies View Related

Pulling Top 3 Within Record Selection

Apr 26, 2007

I need to pull a report that gives me the desired results as show below. I first show the data that is in the table, then below that is the desired result.

What I am trying to do is pull every employee's most recent 3 appraisal Effective Dates within the last 4 years where Rating is different than X.

Sorry I don't reall know how to explain this using code because I seem to be having a block right now. Not sure where to start really.

Any help would be greatly appreciated!! Thanks again!

Records in tblAPPRAISALS Table:

Employee | Appraisal Effective | Rating
A | 1/10/2006 | 5
A | 1/10/2005 | 4
A | 1/10/2004 | 5
A | 1/10/2003 | 5
A | 1/10/2002 | 5
B | 1/10/2006 | 5
B | 1/10/2005 | 5
B | 1/10/2004 | X
B | 1/10/2003 | 5
C | 1/10/2006 | 4
C | 1/10/2005 | 5
C | 1/10/2004 | 5


My current SQL:

SELECT DISTINCT TOP 3 Employee, Appr_Eff as [Appr Effective], Rating_Of_Rcd as [Rating]
FROM tblAPPRAISALS
WHERE Appr_Eff >= DateAdd("YYYY", -4, Date()) AND Rating_Of_Rcd <> "X"
Order by 1, 2 DESC


Results from this Query:

Employee | Appraisal Effective | Rating
A | 1/10/2006 | 5
A | 1/10/2005 | 4
A | 1/10/2004 | 5


Desired Results:

Employee | Appraisal Effective | Rating
A | 1/10/2006 | 5
A | 1/10/2005 | 4
A | 1/10/2004 | 5
B | 1/10/2006 | 5
B | 1/10/2005 | 5
B | 1/10/2003 | 5
C | 1/10/2006 | 4
C | 1/10/2005 | 5
C | 1/10/2004 | 5

View 5 Replies View Related

Pulling A DB Via Remote Admin

Aug 27, 2001

using remote admin program and i need to pul the entire DB onto my local maachine to do some trial runs. I have a static IP so i thought I could just DTS the how system to my computer. Can any one verify that this is the best way of suggest another?
Thanks
Matt

View 2 Replies View Related

Pulling Uniquely When You Can't Use Distinct, Or An ID

May 18, 2006

So here is the problem

I have a table, with an identity in it, I have another table, with that number, it is a one to many relationship.

That table has Fname, Lname inisde of it, some numbers have 1 record, some have 4

Here is the query


Code:


SELECT
FName = ISNULL(UPPER(LTRIM(RTRIM(addr.FName))),'')
, LName = ISNULL(UPPER(LTRIM(RTRIM(addr.LName))) ,'')
, FName2 = ISNULL(UPPER(LTRIM(RTRIM(names.FName))),'')
, LName2 = ISNULL(UPPER(LTRIM(RTRIM(names.LName))) ,'')
, FName3 = ISNULL(UPPER(LTRIM(RTRIM(names.FName))),'')
, LName3 = ISNULL(UPPER(LTRIM(RTRIM(names.LName))) ,'')
, FName4 = ISNULL(UPPER(LTRIM(RTRIM(names.FName))),'')
, LName4 = ISNULL(UPPER(LTRIM(RTRIM(names.LName))) ,'')
, Address1 = ISNULL(UPPER(LTRIM(RTRIM(addr.Address1))) ,'')
, Address2 = ISNULL(UPPER(LTRIM(RTRIM(addr.Address2))) ,'')
, City = ISNULL(UPPER(LTRIM(RTRIM(addr.City))) ,'')
, State = (SELECT StateAbbr FROM ac_States WHERE StateID = addr.StateID)
, addr.Zip

FROM Edina_Class class
LEFT JOIN Edina_Names names
ON names.claimno = class.claimno
INNER JOIN Edina_Address addr
ON class.claimno = addr.claimno
where addr.isactive = 1



What I want is to pull back the unique names, so, if the use only had 1 name, name2-4 would be blank, if the person had 3 names name4 would be blank.

Since "name1" is in the address table, I can pull that one back easy, but what is happening, is the code is taking the first name is finds in the name table and filling in names2 - names4 with it.

I have no idea how to fix the person besides recreating the name to have all of the names per user in 1 record opposed to individual records in the names table.

Hope that made sense.

Thanks

View 5 Replies View Related

Pulling My Hair Out With Locking.

Jan 6, 2006

SQL Server 2000 - Backend
Access 2000 Runtime - Front End
Connecting via ODBC

I have read loads and loads of examples and looked at other sources of info for help on this but am struggleing big time.

I have multiple users working in the same database table. The problem is they often get an error message about the record has been changed and would they like to save the changes to clipboard etc etc.

I basicly want to implement pessimistic locking for my tables. So once a user has started to edit that record nobody else can get to it.

Can anybody help?

Many thanks

View 5 Replies View Related

Pulling Max (date) Not Correct

Dec 21, 2012

Code:
SELECT P.ID, P.QTY, T_DATE
FROM PARTS P
INNER JOIN INVENTORY I ON P.ID = I.PART_ID
WHERE P.QTY > 0 AND I.CODE = 'R'
GROUP BY P.ID, P.QTY, I.T_DATE
HAVING MAX(T_DATE) !> DATEADD(MONTH,-12,GETDATE())

[Code] ....

I am trying to make the sql only pull records where the highest date stored is older than a year ago.

So, based on today's date 12/21/2012:

if the highest (max) T_DATE is 3/12/2012 => don't pull that record
if the highest (max) T_DATE is 11/30/2011 => pull that record into the recordset

the statement is off, it is pulling records that should not be included.

View 4 Replies View Related

Replication (pulling A Subscription)

May 19, 2004

I am trying to pull subscription for a database but I always get the error message ...
Error 15004: Name cannot be null
What exactly have I done wrong
Plaese help
Thanks
Nneka Echebe

View 1 Replies View Related

Pulling Data With Apostrophe

Aug 6, 2013

I am having a problem trying to pull data that has apostrophe in them. How can I do this? I get this as an error

Msg 105, Level 15, State 1, Line 14
Unclosed quotation mark after the character string ''.

Select
Name
From Table
Where Name IN (CHILDREN'S ANES ASSOCS-CHOP,CHILDREN'S HEALTHCARE-CHOP,CHILDREN'S PSYCH ASSOC-CHOP,CHILDREN'S SURGICAL ASSOC-CHOP)

View 4 Replies View Related

Pulling Progress Data

Jun 26, 2006

I'm trying to pull data from about 30 progress databases using DTS andscheduling the jobs to run monthly. I'd like to pull data betweenspecific dates, but for some reason, I can't figure out how to filterthe data on the progress side.I want to run a query that will pull all data fromprior-month/8/current-yearandcurrent-month/15/current-yearI'll also have to account for when it's january, make it december ofthe year before.Any ideas?thanks,M@

View 1 Replies View Related







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