Select particular text from a varying lenght of text value field [closed] - sql-server

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a column with following rows in it
"XX - Make a determination from receipt of request within 15 calendar days"
"Make a determination from receipt of request or necessary info within 2 business days"
"YYYYYYY - Make a determination from receipt of request within 72 calendar hours"
"ZZZZZZZZZZZ - Make a determination from receipt of request within 30 calendar days"
and all types of different combinations with a similar pattern of
"XXXXXXXXXXXXXXXXXXXXX" from "text I want to get" within ZZZZZZZZZZZZZZZZZZZZ
The length of X and Z changes and so does the text between from and within but the from and within always exists in the text. How do I make a query to get the text I want to get into a table variable so that I compare it against other columns in the same table and see if they match or not?
I have the table variable and scalar variable in place to get the values. I just need the proper select statement.

This is really ugly. Fix the table and stop storing different data points inside a string you need to parse like this every time. If your supervisor doesn't understand why this is bad, ask him if he likes to re-program his remote control every time he turns the TV on.
SET NOCOUNT ON;
DECLARE #t TABLE(c VARCHAR(8000));
INSERT #t VALUES
('XX - Make...ion from receipt of request within 15 calendar days'),
('Make a de...ion from receipt of request or necessary info within 2 business days'),
('YYYYYYY - Make...ion from receipt of request within 72 calendar hours'),
('ZZZZZZZZZZZ - Make...ion from receipt of request within 30 calendar days');
SELECT SUBSTRING(c, 1, CHARINDEX('within', c)-1) FROM
(SELECT c = SUBSTRING(c, CHARINDEX('from', c) + 5, 8000) FROM #t) AS x;
Results:
receipt of request
receipt of request or necessary info
receipt of request
receipt of request

Related

Return Filter Quadrants for Search Results [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
Working on a search page. My search results are working but I also need to provide filter choices. One of these choices are a set of price quadrants with product counts. So basically in the result set I have to grab the lowest price and the highest price, then equally break it into 4 groupings and then return those groupings with product counts for each.
So we returned back 49 products, the lowest priced product was $10 and the highest priced products was $110. I have to re-calculate this for every set of search results we're filtering so I can't hard code the floor and ceiling values.
So it would look like this with the number in parenthesis being the number of returned products with a value falling inside that quadrant.
$10.00 to $35.00 (2)
$35.01 to $60.00 (12)
$60.01 to $85.00 (0)
$85.01 to $110.00 (35)
I'm trying to do this in a single SELECT statement because we want to run it off the search results temporary table if the user asks for it.
I keep hitting brick walls trying to write this and can't seem to get very far.
I couldn't get it to work in a single statement, but I was able to get it to work. We created a Numbers table called [Numbers] that I'm using...
DECLARE #priceFloor money; DECLARE #priceCeiling money; DECLARE #priceRange int;
SELECT #PriceFloor = FLOOR(MIN(price)) , #PriceCeiling = CEILING(Max(price)),
#PriceRange = CEILING(Max(price))/4
FROM #TempSearchResults;
WITH priceFilterCTE AS
(
SELECT Number * #PriceRange AS FromPrice, (Number * #PriceRange) + #PriceRange -.01 AS ToPrice
FROM Numbers
WHERE Number BETWEEN 0 AND 3
)
SELECT CAST(FromPrice AS VARCHAR(20)) + ' to ' + CAST(ToPrice AS VARCHAR(20)) AS Price,
(
SELECT COUNT(1)
FROM #TempSearchResults
WHERE price BETWEEN priceFilterCTE.FromPrice AND priceFilterCTE.ToPrice
) AS [COUNT]
FROM priceFilterCTE
Return looks like....
PRICE COUNT
0 to 798.99 949
799 to 1597.99 162
1598 to 2396.99 32
2397 to 3195.99 7

Query the SO data explorer for questions with 4 close votes within a specific tag

I am trying to build a query that displays the ID's of questions with 4 close votes within a particular tag. I do not care about the date the question was posted all I want is just questions with 4 closed votes so I can do some moderation in my free time and go through them and possibly get some of them put on hold or closed.
SO data explorer has a menu on the right where you can see the available columns.
My specific problem is that I can't seem to find the correct table & column that stores the current close votes count.
I tried something like this but I am failing to get any results
select COUNT(PostId) from Votes where PostId = '19577105' and VoteTypeId = '6'
Any pointer in the right direction is appreciated.
SELECT
Posts.ID
FROM
Posts
INNER JOIN Votes ON Posts.ID = Votes.PostID
WHERE
Posts.PostTypeID = 1
AND Posts.Tags LIKE '%C#%'
AND Votes.VoteTypeID = 6
GROUP BY
Posts.ID
HAVING
COUNT(DISTINCT Votes.ID) > 4
This takes a while to run so could probably be optimized. The Tag filter could probably use full text search which may be faster if it is enabled.

ORACLE select lacks row [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I use ORACLE setup RAC cluster.
My problem is when DB got problem (still dont know the reason ) my sql select lacks rows
example:
select *
from student_detail
where student_id = 1231
should return 10 row data of student have id 1231, but in this case just return 6 rows
can anybody help me to understand this problem!
As a general observation, an Oracle SELECT always returns the correct number of rows. If the result set does not match your expectation then there is a problem with your understanding.
For instance you may have miscounted the number of rows with student_id = 1231. If the query returns only six rows how do you know there are supposed to be ten? It might not be as simple as eyeballing ...
select * from student_detail
order by student_id
... if student_id has a varchar2 datatype and some IDs are suffixed with stray spaces. A query like this will diagnose that problem:
select student_id, count(*)
from student_detail
group by student_id
order by student_id
Other possible causes? A misleading view? Row Level Security restricting the result set? Some bizarre client-side configuration which only shows the first six rows instead of the entire set?
You mention RAC. RAC uses a mechanism called the Global Cache Service Process to transmit changed data to different nodes. It is possible you are experiencing a failure in this process. Talk to your DBA and get them to investigate.
Maybe, the data should be wrong.
for example, if the data of user_id is '1231', that's not wrong, but if the data is left gap
like ' 1231', you can't see the data.
' 1231 ' , '1231 ' also can not be printed out.
The solution is when you insert some data, use the function 'trim' or 'replace'...
trim is only remove left gap.

Unable to show report in desire format [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I asked this question before and someone vote down myquestion saying that this question is not valid. I have spent three days on this problem. So please if you do not understand it , it does not mean that the question is invalid. Here it is:
I have created a SSRS report. I am facing problem with respect to page break and Grouping.
Here is the out put of my report.
On each page I want to show record group by Landing Date and Buyer Name.
That is on first page following should be shown:
Buyer Name Landing Date Actual Price
SHETLAND 06-Jan-05 100989.754569257
On second page:
Buyer Name Landing Date Actual Price
SHETLAND 11-Jan-05 1096677.95045137
On third page:
Buyer Name Landing Date Actual Price
FRESH 14-Jan-05 300080.972657965
SHETLAND 14-Jan-05 157372.157557842
==========================================================================
I applied Grouping using group properties , but no effect. Basically I want to show records with same landing date on one page.
Try to create Grouping on two level (nested). That is first group by Landing Date and then right click on newly created group and create a child group . and in child group create expression to group by Buyer Name. Hope it will work.
You need to add a row group with the group by on Landing Date and Buyer name, and then in the group properties tick the check box for 'Add a page break between instances of a group'

Automatic generate a sales order line for every sales order [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Im experimenting with Dynamics Nav 2009.
Is there a way to automatically insert a sales line every time I make a new sales order?
I want postage to be included everytime Im making a new sales order.
There are two ways to solve this, one without programming, and one almost without programming.
If you postage line is a standard "charge" added to all orders then you can actually use the "Invoice Discount" functionality. Besides allowing you to assign an actual discount (typically being applied if the order is above a specific amount), then you can also use the functionality to add a "Service Charge". Either to be inserted on all orders, or only if the order total is below a certain "Minimum Amount".
You set it up by specifying the "Invoice Discount Code" field on the Customers and enable the automatic calculation in the "Calc. Inv. Disc." field in "Sales & Receivable Setup" table. The postage lines are not inserted as actual sales lines, but are calculated and applied when posting (or using the total / statistics button).
The other option is the use the "Standard Sales Codes". Here you can specify a number standard lines which are to be inserted whenever the standard sales code are selected. This is where I said a little programming is required, as the system doesn't automatically insert the lines. But you can insert a call to the function to insert the lines automatically when the customer no. has been entered.
This change would most likely require a modification from your NAV Partner.
The modification could add C/AL code to automatically insert a new Sales Line every time a new Sales Header record is created.
OnInsert()
SalesLine.INIT;
SalesLine."Document Type" := "Document Type";
SalesLine."Document No." := "No.";
SalesLine."Line No." := 0;
// Additional Code
SalesLine.INSERT(TRUE);

Resources