SQL Server 2008 :: Display All Months Even If Values Are NULL

May 13, 2015

I am stuck on a query where I need to display all the month year values even if the corresponding count_booking values are NULL. The requirement is to display the 13 month year period from current date.

For e.g. if the date exists in the current month then starting from May 15 go all the way back to Apr 14.

My current query works in terms of displaying all the 13 months if the count_booking values exist for all the months. However, if some months are missing the values then those months don't show up.how to display all the months even if the values are NULL ? Query below:

SELECT COUNT(m.BOOKING_ID) AS count_booking, LEFT(DATENAME(MONTH, m.CREATE_DT), 3) + ' ' + RIGHT('00' + CAST(YEAR(m.CREATE_DT) AS VARCHAR), 2)
AS month_name
FROM MG_BOOKING AS m
WHERE (m.CREATE_DT >= DATEADD(m, - 13, GETDATE()))

[code]...

View 8 Replies


ADVERTISEMENT

SQL Server 2008 :: Split Values In 12 Months

Oct 16, 2015

I need to split the amount equally into 12 months from Jan 2015 through Dec 2015.There is no date column in the table and the total amount has to be splitted equally.Guess I can't use Pivot here because the date column is not there ...How can I achieve this ?

CREATE TABLE #tbl_data (
Region Varchar(25),
Amount FLOAT,

[code]...

View 4 Replies View Related

SQL Server 2008 :: Values Cannot Be Null - Parameter Name ViewInfo

Jun 11, 2015

Everytime I try to open up SSMS, I get this error:

"Values cannot be null. Parameter Name: ViewInfo"

When I press ok to login, It doesn't show me the database and system dbs aren't expandable.

View 4 Replies View Related

Display Null Values

Jul 17, 2007

Hello,



I'm facing a problem in my reporting.

I have a Customer table where is record various events like CustomerEventId, DateTime, StatusId, StatusTime, GroupId, ...

I also have a status table (Id, Description) and a group table (Id, Description).



I want to create a report where for a selected date range (From ... To ...) i can see (grouped by date) all status's the customer

went in. The possible status are :

Id Description

-------------------------------------

1 status 1

2 status 2

3 status 3

4 status 4



My query looks something like this :



SELECT CustomerEventId, DateTime, CONVERT(varchar, DateTime), 103) AS DATEVAL, StatusId,

status.description as StatusDescription, StatusTime, GroupId, group.Description as GroupDescription

From Customers inner join status on customers.StatusId = status.id

inner join group on customers.GroupId = group.id

Group By CustomerEventId, DateTime, StatusId, status.description, StatusTime, GroupId, group.Description



My reports has 3 parameters (From date, To date, Group)

In my report i have a table with two groups : GroupByDate (grouped on DATEVAL) and GroupByStatus



now my problem : let's say i have values for statusid 1,2 and 4

then my report will only display those 3 status.

How can i display the status where there is no data for :

now it shows :

DATEVAL Occurrences Time

01/07/2007

Status 1 15 125

Status 2 25 366

Status 4 8 66

I would like it to show:

DATEVAL Occurrences Time

01/07/2007

Status 1 15 125

Status 2 25 366

Status 3 0 0

Status 4 8 66



Anybody (i hope i have provide enough details ...)



Vinnie

View 1 Replies View Related

Display Null Values

Apr 17, 2007

Hi,



I have the following problem.

I have created different tables in my database with descriptions in from other tables (example : a table named errors with errorid and errordescription as fields in it)

In a report i want to display the total nr of errors during a certain period for a certain department.

i have created that report with a list (by department). in this list i have a table where i group my errors.

until here all ok. when i display my report it shows all the errors.

but what it doesn't show is all the errors who have value 0 (or errors that didn't occur during that period i defined)



how can i display all my errors, even if they did not occur (0 times)



Greetings

vinnie

View 3 Replies View Related

Display Null Values As 0 On Line Chart

May 16, 2008

I have a report I'm writing and have got a problem that has stumped me.



The data the report is based in is in this format:



Date Type

1/1/08 A

1/3/08 B

3/1/08 C

3/5/08 B

3/10/08 A

3/12/08 C

3/20/08 A





Management wants a report showing a line chart that summarizes the data by Month and by Type. So, there are 2 series depending on the Type and data values are based on the count of each Type. So, in the example above the x-axis group would be month, the values would be count(Type) and there would be 2 series €“ Series 1. A, B and Series 2. C



I€™ve defined the x-axis to be Month(Fields!DateOccured.Value). However, they want the x-axis to show every month for the entire year not just what is in the database. So, I defined the x-axis to have a scale of 1 to 12 and the major interval is set to 1. This displays 1 through 12 on the x-axis.



The problem is when there is no data (null) for a particular month. Instead of showing 0, the line chart does not plot anything and the line is drawn to the next displayed point. So, for example on the data above the line chart would plot:

January

Series 1 €“ Qty. 2 Series 2 €“ Qty. 0

February

Null

March

Series 1 €“ Qty. 3 Series 2 €“ Qty. 2



The line chart would draw a line from January to March skipping February. I need to display the null values as 0 and not null indicating no occurrences for the month rather than no data present.



Thanks!


View 11 Replies View Related

SQL Server 2008 :: Find Patients With Age 6 Months To 5 Years

Mar 3, 2015

formula to return patients ages 6 months to 5 years?

create table dbo.TEST
(
MRN varchar(10),

[Code]....

View 6 Replies View Related

Integration Services :: Excel Source On SSIS 2008 Brings Null Values

Apr 20, 2010

I'm trying to import some XLS files that I receive from some suppliers. The problem is that every time they send some columns with text values but formatted as number. When I read those columns with SSIS Excel Source, they come all with null values.

I don't want to change the columns data types every time, so I would like to know if there's a way to bypass the column types that are already there.

I tried to use both the Jet driver and the Office 12 driver. I've already used the IMEX=1 on ExtendedProperties too with no success. Is there a way to force reading the columns as text, even if they have data types assigned to them?

View 15 Replies View Related

SQL Server 2008 :: Count How Many Records Within 6 Months From Current Record Date

May 27, 2015

My data has 2 fields: Customer Telephone Number, Date of Visit.

Basically I want to add a field ([# of Visits]), which tells me what number of visit the current record is within 6 months.

Customer TN | Date of Visit | # of Visits (Within 6 month - 180 days)
1111 | 01-Jan-2015 | 1
1111 | 06-Jan-2015 | 2
1111 | 30-Jan-2015 | 3
1111 | 05-Apr-2015 | 4
1111 | 07-Jul-2015 | 3

As you can see, the last visit would counts as 3rd because 180 days from 07-Jul-2015 would be Jan-8-2015.

View 3 Replies View Related

SQL Server 2008 :: Calculate Number Of Months Between Dates For Multiple Records?

Oct 7, 2015

I have a challenge and I'm not sure the best route to go. Consider the following dataset.

I have a table of sales. The table has fields for customer number and date of sale. There are 1 - n records for a customer. What I want is a record per customer that has the customer number and the average number of months between purchases. For example, Customer 12345 has made 5 purchases.

CustomerNumber SalesDate
1234 05/15/2010
1234 10/24/2010
1234 02/20/2011
1234 05/02/2012
1234 12/20/2012

What I want to know is the average number of months between the purchases. And do this for each customer.

View 6 Replies View Related

SQL Server 2012 :: Generate Months Based On Previous Values

Jul 7, 2015

I have a data that with month values ranging from jan 2012 till july 2013 with some values associated with it.

I want to generate months automatically after july 2013 till december 2013 in sql something like the below one:

Is there a way in sql to do this?

View 2 Replies View Related

Compressing Multiple Rows With Null Values To One Row With Out Null Values After A Pivot Transform

Jan 25, 2008

I have a pivot transform that pivots a batch type. After the pivot, each batch type has its own row with null values for the other batch types that were pivoted. I want to group two fields and max() the remaining batch types so that the multiple rows are displayed on one row. I tried using the aggregate transform, but since the batch type field is a string, the max() function fails in the package. Is there another transform or can I use the aggragate transform another way so that the max() will work on a string?

-- Ryan

View 7 Replies View Related

Display The Variance Between Two Years In Row With Months In Columns?

Mar 17, 2008

I already read a lot about the inscope-function and how it is used to display variances over time periods. But I don't know where to start, as there is no tutorial how to setup this functionality. What I want to display within the report is the following:





Code Snippet

Months
ProductGroup Article Year 1 2 3 4 5 ....
Bicycles 1020 2007 1500 2000 etc.
2008 3000 3000
Var. abs. 1500 1000
Var. % 100% 50%
1025 2007 0 1000
2008 500 1200
Var. abs. 500 200
Var. % 500% 20%
Motorcycles etc.

View 14 Replies View Related

SQL Server 2012 :: Select Query - Get Result As Month And Values For All Months Whether Or Not Data Exists

Jul 27, 2015

I have a table with dates and values and other columns. In a proc i need to get the result as Month and the values for all the months whether or not the data exists for the month.

The Similar table would be-

create table testing(
DepDate datetime,
val int)
insert into testing values ('2014-01-10 00:00:00.000', 1)
insert into testing values ('2014-05-19 00:00:00.000', 10)
insert into testing values ('2014-08-15 00:00:00.000', 20)
insert into testing values ('2014-11-20 00:00:00.000', 30)

But in result i want the table as -

Month Value

Jan1
Febnull
Marnull
Aprnull
May10
Junnull
Julnull
Aug20
Sepnull
Octnull
Nov30
Decnull

View 9 Replies View Related

SQL Server 2008 :: Display One Row For The Query?

Jan 29, 2015

For the following query, I am trying to fetch only one row (no duplicates) for each BL_ID based on the logic that if I have multiple rows for one BL_ID, then only the one which has the largest LEG_SEQ_NBR should be displayed and the other rows should be ignored.

I am using the below code get to the above logic:

ROW_NUMBER() OVER (PARTITION BY ITIN.BL_ID ORDER BY ITIN.LEG_SEQ_NBR desc) AS RowNum

select
*
FROM
(
SELECT
TMIS.[BL_ID]
,[POL_NAME]
,[POD_NAME]

[code]....

where rownum in (1,2)

View 6 Replies View Related

SQL Server 2008 :: Display Dates Between A Range

Mar 30, 2015

How to show the dates in between a range. Its hard for me to explain so I have ddl with the original results and then ddl of how I would like the desired outcome.

On the side I have a visit ID I need to show each day logged for each ID. Sometime the Start and End are a single day and sometimes they are a range. I need a row for each date.

CREATE TABLE #Results (VisitID INT, DateFrom DATE, DateTo DATE)
INSERT INTO #Results VALUES (361, '2015-03-07', '2015-03-07'), (361, '2015-03-08', '2015-03-10')
,(48, '2015-03-18', '2015-03-18'),(48, '2015-03-19', '2015-03-23')

SELECT *
FROM #Results
DROP TABLE #Results

[Code] .....

View 5 Replies View Related

SQL Server 2008 :: Can Display All Days In A Range Even With No Data?

Aug 10, 2015

I need to display all the dates within a range even with no data

For example right now my query get the records with the range say...

The range is 7/1/15 thru 7/7/15

I Get...
Joe 7/1/15 xxx
Joe 7/3/15 ccc
Joe 7/5/15 xxx

I want...
Joe 7/1/15 xxx
Joe 7/2/15
Joe 7/3/15 ccc
Joe 7/4/15
Joe 7/5/15 xxx
Joe 7/6/15
Joe 7/7/15

View 9 Replies View Related

SQL Server 2008 :: Display Output Of Table In Given Format?

Aug 19, 2015

I have a table Test123 having three column EmpID,AttribName,AttribValue.

run the below query to generate table structure and data.

Create Table Test123(EmpID int,AttribName varchar(50),AttribValue varchar(50))

insert into Test123 values(1,'Name','X')
insert into Test123 values(1,'Age',50)
insert into Test123 values(1,'Salary',1000)
insert into Test123 values(2,'Name','Y')
insert into Test123 values(2,'Age',30)
insert into Test123 values(2,'Salary',2000)
insert into Test123 values(3,'Name','Z')
insert into Test123 values(3,'Age',35)
insert into Test123 values(3,'Salary','One Hundred')

And I want output in below format.

AttributeValueType
=================
AGE | NUMERIC
NAME | ALPHABET
SALARY | ALPHANUMERIC
==================

View 6 Replies View Related

SQL Server 2008 :: Display List Of Indexes - Add Database Name In Results

Apr 6, 2015

I written a proc to display the list of Indexes But I needed to print the database where the objects do belong to. How I should write the Dynamic script to add the database Id? I thought to use derived table kind of stuff, but unable to find a solution.

ALTER PROC [dbo].[USP_INDEXCHECK]
AS
DECLARE @sql NVARCHAR(max)
DECLARE @DB VARCHAR(max)
DECLARE databasecursor CURSOR FOR

[Code] .....

View 2 Replies View Related

Transact SQL :: Making Hours Into Months And Days In 2008 R2?

Aug 5, 2015

I have hours which can be like 32.5 and would like to have them in 1 month 2 Days format.

View 2 Replies View Related

Listing All Months Regardless Of Values

Jun 15, 2005

I have written the following query which returns the number of orders received grouped by the year and month:
SELECT DATEPART(yyyy, order_placeddate) AS year, DATEPART(mm, order_placeddate) AS month, count(order_id) AS orders
FROM orders
GROUP BY DATEPART(yyyy, order_placeddate), DATEPART(mm, order_placeddate)
ORDER BY year, month
year month orders
---- ----- ------
2004 6 17
2004 7 37
2004 8 30
2004 9 42
2004 10 34
2004 11 46
2005 1 25
2005 2 7
2005 4 1
The obvious problem with the above is that it misses out the months that have no orders, i.e. December, March, May, etc.

Is there a way I can amend my query so that it shows all months regardless of whether any orders were placed?

I have thought about trying to LEFT OUTER JOIN the above to a table that has rows with values of 1 – 12, but I’m not convinced this is the answer... and I don’t really know how to do it!

Do let me know if any of the above is unclear – what I’m after is the following:
year month orders
---- ----- ------
2004 6 17
2004 7 37
2004 8 30
2004 9 42
2004 10 34
2004 11 46
2004 12 0
2005 1 25
2005 2 7
2005 3 0
2005 4 1
2005 5 0
Many thanks

View 1 Replies View Related

SQL Server 2008 :: Set Null Does Not Work For More Than One Field

Apr 23, 2015

I have the Person table with the following fields:

Id_Person
Nm_Person
Id_AddressResidential
Id_AddressCommercial

Another table called Address with the following fields:

Id_Address
Ds_Street

I want to make the relationship between these tables so that when deleting a related field address in Person is set to null.the SQL Server allows me to make this relationship in only one field.A person can live and work in the same place. If I delete her address, I want the two Individual fields are set to null.

View 5 Replies View Related

SQL Server 2008 :: Removing Null From Result Set

Aug 25, 2015

I want to remove the nulls from the result set so the result is 1 line. Code and results are below:

SELECT
CustomerNumber,
(case when yearseq = 2012 then isnull(sum(mainPower),0)+isnull(sum(sidePower),0)+isnull(Sum(leftPower),0)
+isnull(Sum(netappPower),0)+isnull(Sum(rightPower),0)+isnull(Sum(lowerPower),0) end) as '2012',
(case when yearseq = 2013 then

[Code] ....

What can I do to my code to remove the Nulls to the entire result is just 1 line?

View 2 Replies View Related

SQL Server 2008 :: How To Get Rid Of NULL In Results From Case When

Sep 21, 2015

I'm trying to get a result set without the NULLs. Here is the code I'm using. I'd like the results to look like:

17285204 90471 090471
17285204 90715 090715
17285204 99396 099396
17285204 99420 099420
17285204 90471 090471
17285204 NULL G0444

create table #Test
(
AppNum varchar(10),
CPT varchar(10),
src char(1)
)
insert into #Test(AppNum, CPT, src) values('17285204','090471','b')

[Code] ...

View 5 Replies View Related

Getting Density Of Values Across Years And Months

Aug 29, 2007

Hi All,

I have the following table "Project"

-------------------------------------------------------------------------------------------
ID Name Start Date End Date
--------------------------------------------------------------------------------------------
001 Project 1 2-2-2003 2-3-2007
002 Project 2 1-24-2003 2-6-2007
003 Project 3 4-10-2005 2-10-2008
004 Project 4 5-20-2006 6-6-2008
...
015 Project 15 2-20-2006 3-3-2009
----------------------------------------------------------------------------------------------
What I want is the the following output.

Output 1:

------------------------------------------------------------------------------------------------------------------------------------------------
Year Projects No. Of Projects Starting Months
------------------------------------------------------------------------------------------------------------------------------------------------
2003 Project 1 , Project 2 2 February, January
2005 Project 3 1 April
2006 Project 4, Project 15 2 May , Feb
------------------------------------------------------------------------------------------------------------------------------------------------

(the order displayed in the months shoudl be in accordance with the order of the projecs in the projects column...)
and also the following

Output 2: (this is optional view...)
-----------------------------------------------------------------------------------------
Year Start Date Project Name
-----------------------------------------------------------------------------------------
2003


February 2 Project 1
January 24 Project 2
2005
April 4 Project 3
2006
May 5 Project 4
February 20 Project 15
-------------------------------------------------------------------------------------------

I am very much in need of Output 1. Could someone help me,




View 5 Replies View Related

SQL Server 2008 :: Allow Null On Data Type Money?

Oct 15, 2015

Should data type money allow nulls? Are there valid arguments both pro and con?

Yes, there is the age-old question regarding how one might interpret a NULL found in any column - does it mean the amount is not known or that the amount is zero (in the case of a numeric type)? You get the drift...

Other than that, though - are there any practical considerations an old data hound ought to be aware of?

View 7 Replies View Related

NULL Values In SQL Server 7.0

Jun 22, 1999

Following SQL Statement is from BOL 7.0 and it doesn't return any data. But when I change the where clause to "WHERE advance IS NULL" it works. I am trying to do something like this in my own stored procedure. It works fine in 6.5 both ways. Is there any parameter to set? or any other problem. Thanks in advance.

SELECT title_id, type, advance
FROM pubs.dbo.titles
WHERE advance = NULL

View 1 Replies View Related

Null Values In Sql Server

Mar 21, 2004

Hi

I am importing an excel spreadsheet into tables in a sql server database using dts. I have one row of information filled out in the excel spreadsheet, but when the dts runs, it imports the information plus 5 extra rows filled with nulls ino the table.

Does anyone know how to fix this?

Thanks

View 2 Replies View Related

Null Values When Quering Sql Server From VC++

Oct 1, 2001

Hello, i´m inserting values in a table defined as above,

/********
create table SERVICE_TYPE (
PK_TYPE numeric(8) not null IDENTITY,
TYPE nvarchar(32) not null unique,
DESCRIPTION nvarchar(256) null default(''),
USER_VISIBLE numeric(1)not null,
constraint PK_SERVICE_TYPE primary key (PK_TYPE)
)
go
**********/

these values are inserted throug ODBC with VC++,
in the case of the DESCRIPTION Column, i´m sending null strings CString(""). this value will be filled after.
What happens is that, when i query the database to show the records in this table, the database shows, for example:

PK_TYPE TYPE DESCRIPTION USER_VISIBLE
--------- ------ ------------------- -------------
1 1 (null) 1

i dont want to show the "(null)" value in the column DESCRIPTION, but a null string like ""

can anyone help me , thanks

Cristovão

View 1 Replies View Related

How Do You Handle Null DateTime Values From SQL Server?

Aug 17, 2005

If myDateTimeColumn contains a <NULL> value.  How do you handle that when reading into a DateTime object in your code?DateTime myDate = Convert.ToDateTime(dr["myDateTimeColumn"]);Does not work, it throws: System.InvalidCastException: Object cannot be cast from DBNull to other types.
I am curious as to what others are doing to handle this?

View 6 Replies View Related

SQL Server 2012 :: Get List Of Last Non Null Values

Feb 10, 2014

I have two tables, a dates table and a values table. They are joined on the date column.The date table has a range, say from today as far as 20 days from now, incrementing by 1 day each row.The values table may have a row for a day, and may not. If the day has a value I want to display that value.If the day does not have a value in the values table I want to display the last known value.

I think this can be done with windowing functions in a set based manner but have not been able to work it out. I have done it procedurally but im not happy with that at all, and really want to see if this is possible in a set based manner.Below is some simplified code to allow testing with sample data.

create table DimDate
(
DateCol date
)
create table TotalsData
(
DateCol date

[code]....

View 6 Replies View Related

SQL Server 2012 :: Pass In Null Values

Sep 20, 2014

The following t-sql 2012 works fine in sql management studio. However when I place it in a .net 2010 web form application, I am told the sql does not work when the parameter values are null. Thus can you tell me what I can change in the sql below that will accept null as 3 possible input values?

SELECT i.[lastName]
,i.[firstName]
,i.[middleName]
,i.[suffix]
,a.[userid]

[code]...

View 1 Replies View Related

SQL Server 2012 :: Null Values With Joins?

Aug 14, 2015

CREATE TABLE A (ID INT IDENTITY (1,1))
CREATE TABLE B (ID INT, EMPID VARCHAR(10))
INSERT INTO A DEFAULT VALUES
GO 5
INSERT INTO B VALUES (1,'E23')
INSERT INTO B VALUES (1,'E24')
INSERT INTO B VALUES (2,'E23')

from the above code i would like to get output like

ID EMPID
1 23
2 23
3 null
4 null
5 null
1 24
2 null
3 null
4 null
5 null

I'm trying like

select a.id, b.empid from (
select * from a cross join (
select distinct empid from b) b
) a

left outer join b on a.id = b.id but i get repetitive rows.

View 7 Replies View Related







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