How to select specific character when you have a different length of characters. For example I have a columm where I have character ":". How to select only ":"?
I have to replace 'MED-40'instead of '30' in an incidentno column of incidents table ,the fiels is varchar(12),now the problem is it is replacing whereever it sees '30' while I want only the leftmost to be replaced for eg
Let '301530' be the incidentno to be replaced if I run
UPDATE incidents_mm set incidentno = replace(incidentno, '30', 'MD-40')where incidentno= '301530'
query i get the ans given below
'MD-4015MD-40'
and I just want the ans to be MD-401530 In short i just want first 2 characters to be replaced is there any way i can do that Thanks in adv
Hi all,Right now I have this SELECT statement:SELECT MUSIC_PK, MUSIC_TITLE, MUSIC_TITLE2, MUSIC_ORIGINAL_SINGER Now I want to add a second SELECT statement (same as above, but with an additional column) if the record was added within the 10 days (while still select other records, I just need to select an additional column). How would I do that? The additional column that I want to select is called MUSIC_NEW (so I can display if the record is new within 10 days.) I have a column in my table named DATE_ADDED, how do I go to calculate if it's within the 10 days since the day it was added to the current time?Thank you very much,Kenny.
Hello all, thanks in advance for any help you might be able to give.
I'm familiar with the Top command but I need something else to help in a project I'm working on.
I would like to select rows 1 through 100000 from a specific table in one query then 100001 through 200000 in a second query and 200001 through 300000 in a third and so on until I have gone through all rows. There happens to be 424000 in the table I'm working on.
Hi, I'm a new DBA and am a rookie when it comes to working with SQL Server 2005. I have been tasked with transfering an Access database to SQL Server 2005. Now I understand to use the import/export wizard, but am having problems fixing an error I am receiving. Here is the error...
Problem I - Copying to [IS_Shared_ServicesTest].[dbo].[tblResource] (Error) Messages * Error 0xc0202009: Data Flow Task: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005. An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "Invalid character value for cast specification". (SQL Server Import and Export Wizard)
* Error 0xc020901c: Data Flow Task: There was an error with input column "Contract Start Date" (115) on input "Destination Input" (80). The column status returned was: "Conversion failed because the data value overflowed the specified type.". (SQL Server Import and Export Wizard)
Here is the short version of the error. I realize that there is an error with the conversion and the error is in tblResource in column Contract Start Date. It is still transfering the column over, and on spot check they seem fine. Should I be really worried about an error? Or is there something that I can do with the Access or SQL server database to fix this?
In the typical Job Cost Reporting world you can easily create SQL Views / Stored Procedures (or create a report) that can return both Job To Date values along with period values for another date range. Something like this:
Job, Phase of Work, Cost Type, UM, Budgeted Cost, Budgeted Quantity, Period Cost, Period Quantity, Period Unit Cost, JTD Cost, JTD Quanity, JTD Unit Cost, Variance between JTD and Period Cost, Variance between JTD and Period Quantity, Variance between JTD and Period Unit Cost
But in the tabular BI world I am not certain how to have these values show up in a pivot table or BI visualization. My current Fact table is essentially every job cost transaction so it is at the most granular level holding Company, Job, Phase of Work, UM, Cost Type, Date, Budget Cost, Budget Quantity, Actual Cost, Actual Quantity. The Budget values only have a value if the entry was updating the budget and the Actual values hold actual cost for each transaction. If you don't restrict by date you have your Budgeted Quantity / Cost and Job To date Cost / Quantity.
I can generate a Pivot table or chart and not restrict by date and I can get all the Budget Totals and the Job To Date Totals when I have the Company, Job, Phase Of Work, Cost Type.
But what if I want to look at a range like last quarter or yesterday or last week. I can indeed filter that data in Pivot Table and get the period values, but now I don't know how to have the Job To Date values show up for comparison purposes.
I am guessing maybe a DAX formula (if using Excel Powerpivot or SQL Tabular Model), but I am at a loss.
So in the BI world how do you get Job To Date totals while also viewing the data for a period of time?
Here are some example graphs we would want to show for a single Job. Let's say we want to show the 10 worst performing cost distributions.
I would want a graph to show the cost distribution and for each cost distribution it would show Budgeted Cost, Period Cost, Job To Date Cost.I would want a graph to show the cost distribution and for each cost distribution it would show Budgeted Unit / Cost, Period Unit / Cost, Job To Date Unit / Cost.I would want a graph to show the cost distribution and the variance between JTD and Budget and Period and Budget.
As you can see it all stems around seeing JTD and Budget values vs Period Values. Here is a visualization that may work. I am using PivotTable filtered on one Company, Job, Phase of Work. I can see the sum of actual cost which is the totals for the date range I provided. But I still want to see the JTD totals for that Phase of Work and Cost Types and actually the Budget Totals as that is sort of a JTD, but for budget... especially if I want to compare Budget vs JTD vs Actual.
I am attempting to write a SQL query that retrieves info processed between two times (ie. 2:00 pm to 6:00 pm) during a date range (ie. 8/1/06 to 8/14/06)... I am new to SQL and am perplexed... I have referenced several texts, but have not found a solution. Even being pointed in the right direction would be greatly appreciated!!
At the following MDX code , I want to get the aggregate of measure only for members that are also in the specified last time (like in examp 01/06/2015) . I tried existing and exists, but without any lack.
WITH MEMBER A AS (b)+(C) MEMBER [Measures].[Aggregate] AS Aggregate(DAYTIME].[Month].&[2013-01-01T00:00:00]:[DAYTIME].[Month].&[2015-06-01T00:00:00], ([Measures].[D])
I have 2 tables, one is table A which stores Resources Assign to work for a certain period. The structure is as below
Name StartDate EndDate Tan 2015-04-01 08:30:00.000 2015-04-01 16:30:00.000 Max 2015-04-01 08:30:00.000 2015-04-01 16:30:00.000 Alan 2015-04-01 16:30:00.000 2015-04-02 00:30:00.000
The table B stores the item process time. The structure is as below
Item ProcessStartDate ProcessEndDate V 2015-04-01 09:30:10.000 2015-04-01 09:34:45.000 Q 2015-04-01 10:39:01.000 2015-04-01 10:41:11.000 W 2015-04-01 11:44:00.000 2015-04-01 11:46:25.000 A 2015-04-01 16:40:10.000 2015-04-01 16:42:45.000 B 2015-04-01 16:43:01.000 2015-04-01 16:45:11.000 C 2015-04-01 16:47:00.000 2015-04-01 16:49:25.000
I need to select the item which process in 2015-04-01 16:40:00 and 2015-04-01 17:30:00. Beside that I need to know how many resource is assigned to process the item in that period of time. I only has the start date is 2015-04-01 16:40:00 and end date is 2015-04-01 17:30:00. How I can select the data from both tables. There is no need for JOIN, just seperate selections.
Another item process time is in 2015-04-01 10:00:00 and 2015-04-04 11:50:59.
The result expected is
Table A
Name StartDate EndDate Alan 2015-04-01 16:30:00.000 2015-04-02 00:30:00.000
Table B
Item ProcessStartDate ProcessEndDate A 2015-04-01 16:30:10.000 2015-04-01 16:32:45.000 B 2015-04-01 16:33:01.000 2015-04-01 16:35:11.000 C 2015-04-01 16:37:00.000 2015-04-02 16:39:25.000
Scenario 2 expected result
Table A
Name StartDate EndDate Tan 2015-04-01 08:30:00.000 2015-04-01 16:30:00.000 Max 2015-04-01 08:30:00.000 2015-04-01 16:30:00.000
I would like to generate a report based on age from an existing table. All I have is birthdate column to subtract from getdate(). I would like to create age bracket columns. The example below shows that there is 150 people aged 0-4 years old, 75 people aged 5-9, 225 people aged 10-14, etc. Would I use a case statement? Would I use the COALESCE function? I can come up with the calculations and the columns, I just can't fuse the values of my made up columns to result in one row. I need help, please....
here's a sample of what I want the query output to look like: 0-4 5-9 10-14 15-17 ---------------------- 150 75 225 35
begin SET @STR='INSERT INTO tbl_Level1' + '(' + @columnName + ',orgID' + ')' + 'Values' + '(' + @Level1Name + ',' + @orgID + ')'
EXEC @STR
ERROR :- Conversion failed when converting the varchar value 'INSERT INTO tbl_Level1 (Level1Name_HIN,orgID ) Values (@Level1Name,' to data type int. pls help me out
Hello,I have a table that lists a number of available time slots for a party venue. I want a user to select a particular time slot and have the query show results for that time slot plus two time slots before and two time slots after the user's selection. If the user selects a time slot that is the first of the day, I still want that user to be shown 5 results including the one he selected. The same goes for the last time slot of the day. Can anyone help me with the SQL statement? Thank you very much in advance! Mark
I need to run reports from our database that stores IP addresses when a software license is used. So, I need to know how to run SQL queries to retrieve certain IP addresses from specified ranges. For example:
192.168.1.0 - 192.168.2.255
192.168.3.11 - 192.168.7.128
10.10.10.8 - 10.10.12.255
What commands would help me accomplish pulling all IP addresses in a range. I know I would have to run multiple reports for each range. I tried using the "between" function and "less than/greater than" functions, but I received mixed results. For example:
SELECT * FROM testtable WHERE ip LIKE '192.168.[1-2].[0-255]'
I also tried -
SELECT * FROM testtable WHERE ip>'192.168.1.0' and ip<'192.168.2.255'
Any help would be greatly appreciated! Thanks in advance!
I have a FileConsumptionDetail table which has [DataTime] every 30 minutes. Also, I have a schedule table with has range time and with certain condition.
Now I would like to query against these 2 tables what is the best approach to handle to do this due the process load is around 20,000 records. The end of result is sum of the Value1 of FileConsumptionDetail with the relevat schedule. I can probably using cursor and loop the 20,000 records of the data and check one by one whether that value is applied on that schedule table. Overkill .. I guess?
IsMonday - IsSunday is basically a flag for each day if it's a daily type of schedule. IsJan - isDec is a flag for each month if it's a monthly type of schedule.
Regarding 2nd table design, i am not sure this is a best approach though and I am happy to change if it's easy to query.
Hope this clear and I am appreciated your comment.
I have a table called Event, this table has two fields called StartDate and FinishDate. On my application I want the user to be able to search for all the events for a certain date range. I am having some trouble getting my head around the code and was wondering if someone could offer some advice.
Some more details... the user can enter a from date, a to date or both. I can have separate sql code for each situation. The event.startdate and event.finishdate are never null and may contain a time value.
Hi,I have a query which works for one day:SELECT SOME_COL AS something, SOME_COL2 AS something2 FROM myTableWHERE DATE = '2007-05-11' AND SOME_STAT 1Returnssomething something 21 23 4How do I get this to work for a date range (e.g. DATE '2007-05-09')where I get:date something something22007-05-09 1 22007-05-09 3 42007-05-10 1 22007-05-10 3 42007-05-11 1 22007-05-11 3 4Thanks in advance!
Hi,Need help in optimizing a query in SQL Server.Following is the problem statement.There are two tables;1st table (t1) has a KEY ( char(8) ) column, with a clustered index.this is not the primary key. The table can have billions of records;in test environment, we are having 3,000,000 records2nd table (t2) has two columns a from_Range and to_Range, bothchar(8). this table has lesser number of records, in thousands.Clustered index is on the primary key.However there is no relation whatsoever between the KEY and thefrom/to range.We need to find matching records where Key is found between the fromand to range :select t1.id, t2.id from t1, t2where t1.KEY between t2.from_range and t2.to_range( The ids form part of primary keys in both tables. )The plan shows a loop, with t1 using clustered index of KEY and t2using clustered index of the primary key.This query is taking around 14 seconds on SQL server 2000 in win2kprowith P4 and 512 MB RAM.Is there any way this can be reducd to a subsecond performance ? Thisquery forms the core of most of the processing, and any reduction herewill have recursive effect all over.Thanks in advance,roy.
I use oledb (ACCESS database) in my application. i want to build a query to retrieve the number of Bookings from my Booking table where the appointment_date_time.timeOfADay is in range of 9am-12pm or 14pm- 7pm, that is (>= 9 and <12) or (>= 14 and < 17). Please help to build the query,
I found some query sample like:
select * from tblstudents where classID='1' and studentstartdate between ('2004-12-03') and ('2004-12-12')
or
WHERE DateField BETWEEN @StartDate AND @EndDate
But I dont want to search year and month and day, i just want to search the actual hour of a day. i am stuck with the syntax, please help
item custclass totalcustclass ------------------------- 06-5841 INST-CLINPRAC 1 06-5841 INST-MKT/MEDIA 2 06-5841 PROGRAM 1 06-5841 STANDARD 4 06-5845 STANDARD 1 AX-048 INST-MKT/MEDIA 4 KT-048 PROGRAM 2 KT-048 STANDARD 4
i want condition like if item is starting with number then totalcustclass whcih is count(*) remain same giving correct results...but if item startign with ascii character then totalcustclass r getting double so i have to /2..
i want results:
item custclass totalcustclass ------------------------- 06-5841 INST-CLINPRAC 1 06-5841 INST-MKT/MEDIA 2 06-5841 PROGRAM 1 06-5841 STANDARD 4 06-5845 STANDARD 1 AX-048 INST-MKT/MEDIA 2 KT-048 PROGRAM 1 KT-048 STANDARD 2
select item, custclass,
case when item is <ascii> then count(custclass)/2 else count(custclass) as totalcustclass
from itemcustclass
can anyone tell me what condition will come in case?
I need SQL to determine what the date range for the previous month was, ie Start date 11/01/01 for 11/30/01. The results will populate a drop down box for user queries.
I have two columns, where I have the start and stop numbers (and each of them ordered asc). I would like to get a query that will tell me the missing range.
For example, after the first row, the second row is now 2617 and 3775. However, I would like to know the missing values, i.e. 2297 for start and 2616 for stop and so on as we go down the series. Thanks in advance to any help provided!
hi, i'm using sql sserver 2005 and i have a time that i need to change to a datetime query (from the start of the day to the end of the day), whats the syntax for that? thx
Here is tested schemaif exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[TestTable]') and OBJECTPROPERTY(id, N'IsUserTable')= 1)drop table [dbo].[TestTable]GOCREATE TABLE [dbo].[TestTable] ([SerialNumber] [char] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[test1] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[test2] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[test3] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[test4] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ON [PRIMARY]GOinsert into testtable values ('123','pass',null,'fail','skip')insert into testtable values ('456','fail',null,'pass','skip')insert into testtable values ('789',null,'fail','skip','pass')insert into testtable values ('345','pass','pass','pass','fail')I would like to fetch the COLUMNNAME where the value is fail.Basically I need to know which test failed, test1, test2, test3 ortest4?Is this possible?