Transact SQL :: IsNull From Multi Column
May 13, 2015How to replace this Case When
SELECT CASE WHEN Col_1 IS NULL THEN -1 ELSE Col_2 END AS C
FROM MyTable
How to replace this Case When
SELECT CASE WHEN Col_1 IS NULL THEN -1 ELSE Col_2 END AS C
FROM MyTable
I am in assumption that we cannot do NULL value comparison in where clause directly (results will not be proper) we have to use ISNULL. Is my understanding correct? Is using ISNULL efficient when we have to this operation for large volume?
View 5 Replies View RelatedI am having table like below,
Period Pointvaluemonth area
NULLNULLNULLApril tn
NULLNULLNULLMaytn
NULLNULLNULLJunetn
NULLNULLNULLJulytn
NULLNULLNULLAugusttn
201109 100 10Septembertn
[Code] ....
Then i want to copy september value for october and november and Jan value for feb & mar like next null values should get replaced with previous not null value ...
My desired output is ,
Expected Output is…..
Period Pointvaluemonth area
NULLNULLNULLApril tn
NULLNULLNULLMay tn
NULLNULLNULLJune tn
NULLNULLNULLJuly tn
NULLNULLNULLAugust tn
201109 100 10September tn
[Code] ....
I have a field called PPH and this field type float. so, this field could be null, 0.0, or values. I am using case statement:
[PPH] = case when h.HoursFloat = 0 then 0 else
round(s.Pledges / h.HoursFloat,2) end,
I am trying to add where if h.HourFloat is null then 0 but, it does not work. I have tried different ways such as
[PPH] = CASE isnull (h.HoursFloat,0)
when 0 then 0 else ....
How to add another condition to check on null then 0.
Why don't i ever get return value of 1 when the following binary column (profSignature) is null?
RETURN SELECT ISNULL(profSignature, profSignature) FROM mpProfiles WHERE ApplicantID = CAST(@CID AS INT) AND ProfileID = CAST(@PID AS INT)
i have a derived column which contains the days of a month from 1 to 31
I have this expression for column 1:
(DT_R4)([1] == 4 ? 0.5 : ISNULL([1]) ? 0.0 : 1.0)
But the ISNULL function will not work. I am sure, there are some NULL Values in Column [1] but i get all the Time the value 1.0 back.
I need the Value 0 instead of NULL to calculate the days in an extra Column.
So that i have in the end a result column which have values for example: 4,5 or 5,5 .why ISNULL is not working?
I am trying to exclude records from a table where the ID column is the same but the Mail code Column is multi-valued.For Example: (the table looks like....)
ID Mail_code
111111 XNT
111111 N11
111111 XNC
222222 XNC
222222 XNL
333333 XNC
So, if there is any ID that has a value of XNC, I want to exclude the ID all together from my output regardless of the other values.
I have two tables, one a data table, the other a product table. I want to perform a join on the two tables with values distributed into columns based on the value in the month field.
data_table
product_code month value
350 1 10
350 2 20
350 3 30
product_table
product_code profit_center
350 4520
result_view
product_code profit_center mon1 mon2 mon3
350 4520 10 20 30
My current query gives the following result
result_view
product_code profit_center mon1 mon2 mon3
350 4520 10 0 0
350 4520 0 20 0
350 4520 0 0 30
Any direction toward a solution would be appreciated. Am using SS2005.
Hi,Would like to know the performance differenece between Multi-columnIndex vs Single Column Indexes. Let's say I have a table with col1,col2, col3 along with a primary key column and non-indexed columns.In queries, I will use col1, col2, and col3 together and some timesjust one or two of these three columns. My questions is, should Icreate one index contains col1, col2, and col3, or create 3 seperatedcolumns. I.e. each column has its own index. Any performancedifference?Thanks a lot.
View 1 Replies View RelatedIn my report i would have 2 groups.
The first group should cause a real page break, the secound group should cause a column break.
Any idea on how to realize this, i've been playing with quite some settings but .....
So, any help ...
Have a table with a structure like:
FIELD_A
FIELD_B
FIELD_C
FIELD_D
AMOUNT
DATA_A1
DATA_B1
DATA_C2
DATA_D2
37540
[Code] ....
In such a case, devising a dynamic cross-tab query, to cover all the items, and result like a pivot like the following to represent the data in a multi-header pivot like following:
DATA_C1
DATA_C1
DATA_C1
DATA_C2
DATA_C2
DATA_C2
[Code] ....
I have a sp where query is as below.
DECLARE @ServerCIName varchar(5000)
SELECT * FROM dbo.INC
WHERE Status in ('Assigned','In Progress','Pending')
and Description like '%' + (Select * from SplitDelimiterString(@ServerName,',')) + '%'
and (select DATEADD(dd, DATEDIFF(dd, 0, (Submit_Date)), 0)) = (select DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0))
In place of "and Description like '%' + (Select * from SplitDelimiterString(@ServerName,',')) + '%' ", if I use "and Description like '%' + @ServerName + '%' " and pass a single value, it works.
But @ServerName contains multiple values and it is dynamic (not constant).
How do I query the data?
How can I calculate a DateTime column by merging values from a Date column and only the time part of a DateTime column?
View 5 Replies View RelatedI have 6 columns:
Column1a, Column1, Column2a, Column2, Column3a, Column3
I need a statement that will go through the whole table as follows:
For each row, if column3 is not null then return column3 as columnB and column3a as ColumnA.
If column3 is null then if column2 is not null then return column2 as columnB and column2a as columnA.
If column3 & column2 is null then return column1 as columnB and column1a as columnA.
Any ideas?
Thanks!
Hi there,
My 'where' clause contains the following...
startdate <= @Date AND enddate > @Date
Should I put one index on 'startDate' and another on 'endDate' or should I have one index that covers both columns?
I don't know what the difference would be.
Cheers, XF.
TABLE1
======================
PriceList
---------
1
2
3
1
2
3
1
2
3
Price
-----
777
888
999
777
888
999
777
888
999
(pretend these columns are side by side)
======================
I need to make a query to:
SELECT PRICE AS 'PRICE1' WHERE PRICELIST = 1
AND SELECT PRICE AS 'PRICE2' WHERE PRICELIST = 2
AND SELECT PRICE AS 'PRICE3' WHERE PRICELIST = 3
the output that i want is:
PRICE1
------
777
777
777
PRICE2
------
888
888
888
PRICE3
-----
999
999
999
(pretend these columns are also side by side)
Hi All,
I have the following Ex:
Table A
Col A <- Col that I need to check against
Col B
Col C <- Sum this col
So if Col A has the following values:
Col A Col C
2 10.00
4 15.00
2 25.00
4 15.00
3 10.00
3 5.00
7 4.00
9 20.00
I need to bring back the sums of 2, 4 and 3 in one resultset. How would I do this?
Thanks,
JJ
Hi,
I have a [TestTable] table with three rows. The pair of columns [Test1] and [Test2] are id, the [Test3] is a data column. First, I get a table variable with list of id pairs. Next, I would like to update the rows of that ids. However, I have not found the elegant way how to do it. For one column it is simple, just IN clause, which does not work (or I could not find how) for multi-columns. Does someone have a hint?
Thanks,
Martin
Note: The example bellow is dummy; on the other hand, I hope it shows the important points. Please, do not beat me on syntax errors.
Code Block
DECLARE @MyTableVar table(
Test1 int NOT NULL,
Test2 int NOT NULL
);
SELECT [Test1],[Test2] INTO @MyTableVar FROM [TestTable] WHERE [Test3] = '%dd%';
UPDATE [TestTable] SET [Test3] = [Test3] + 'ds'
WHERE ([Test1], [Test2]) IN (SELECT [Test1], [Test2] FROM @MyTableVar);
Is it possible to create multi column keys in SQL Express? If so, how?
Thanks
MisterT
Hi,
I am trying to use a multi column report as a subreport. I want to know how can I do it without loosing multi column.
Thanks,
-Rohit
What I need to do is to create 3 columns with 3 different aliases from the same table that will return all the values during the following conditions:
when pricelist = 1
when pricelist = 2
when pricelist = 3
pricelist
--------
1
2
3
Price
--------
912 -- (linked with 1)
234 -- (linked with 3)
56 -- (linked with 2)
3245 -- (linked with 3)
234 -- (linked with 1)
65 -- (linked with 2)
these 2 columns are in the same table^^
so what i want my query to generate is:
Price1
--------
912
234
Price2
--------
56
65
Price3
--------
234
3245
Any help is apprecieated, thanks
if the above does not make sense to you maybe this will:
"can you make 3 aliases of the same column and only display the rows inside each column where pricelist = 1 for the 1st alias... where price = 2 for the 2nd alias...where pricelist = 3 for the 3rd alias"
I have a 2 coulmns report ,one group ,when I print the report,it does not paging correctly.For example,suppose every column can display 20 rows, if every group has 20-40 rows ,the print is ok,it can paging correctly,but if one group has 10 rows or more than 40 and less than 60,the two groups will print on one paper,how can I print the every group on different paper?
Any advice would be much appreciated.
Thanks.
I've added a link to a sample on how my test-column report renders.
http://www.leboeuf.be/MSDN/Dagelijkse%20Verkoop%20Merk.pdf
Any idea what's happening, while normally previewing the report (column by page) this problem doesn't occur .... The rendering is the same to TIFF
http://www.leboeuf.be/MSDN/Dagelijkse%20Verkoop%20Merk.tif
Any suggestion on what is the problem and even better, if there is a solution.
Hi,
I have created a multi column report (2 columns), which is working fine. However, I need to have a chart on the same report, but it needs to be the width of the page, and not just the width of one column.
If I could put the chart in the report footer / header that would be perfect, but obviously I can't!
Has anyone else come across this, and any ideas / suggestions you have would be appreciated!
Cheers
Chris
I have a table with a data cell which is printing top-to-down
1
2
3
4
5
6
7
8
I want it to print like
1 2 3 4 5 6 7
How to do this??
The cell is in a group detials sections. and I am using Reporting Services 2000 with VS.NET 2003
Thanks in Advance
I am trying to get a simple list to wrap and print in multiple columns on my report. I have indicated 3 multi-columns in the report properties and see the multiple columns in the layout, but I must need to do something else because the report is still printing in one column to multiple pages. This should all fit on 1 page if the list will wrap or snake as it says it the directions for using multi-column reports.
Any help would be appreciated. Thanks
Hi,
I have got a column which should multi languages data(Chinese,English etc).
Source for this data is Excel.
I have kept this column DataType as NVARCHAR but Chinese data is shown as 'Boxes'.But when i copy this and paste on Query pane i get proper data.
Is the first thing doable?
Hoe can i accomplish this?
Thnks
I have the following table
Table Name EmployeeInformation
EmployeeID EmployeeFirstName EmployeeLastName
1 |John |Baker
2 |Carl |Lennon
3 |Marion |Herbert
Table Name PeriodInformation
PeriodID PeriodStart PeriodEnd
1 |1/1/14 |12/30/14
2 |1/1/15 |12/30/15
[code]...
I want a query to join all this tables based on EmployeeID, PeriodID and LeaveTypeID sum of LeaveEntitlement.LeaveEntitlementDaysNumber based on LeaveTypeID AS EntitleAnnaul and AS EntitleSick and sum AssignedLeave.AssignedLeaveDaysNumber based on LeaveTypeID AS AssignedAnnaul and AS AssignedSick and subtract EntitleAnnaul from AssignedAnnual based on LeaveTypeID AS AnnualBalance and subtract EntitleSick from AssignedSick based on LeaveTypeID AS SickBalance
and the table should be shown as below after executing the query
EmployeeID, EmployeeFirstName, EmployeeLastName, PeriodID, PeriodStart, PeriodEnd, EntitleAnnual, AssignedAnnual, AnnualBalance, EntitleSick, AssignedSick, SickBalance
I am having issues trying to write a query that would provide me the unique GUID numbers associated with a distinct PID if the unique GUID's > 1. To summarize, I need a query that just shows which PID's have more than one unique GUID. A PID could have multiple GUID's that are the same, I'm looking for the PID's that have multiple GUID's that are different/unique.
Table1
GUID PID
GUID1 PID1
GUID1 PID1
GUID1 PID1
GUID2 PID1
GUID3 PID2
GUID3 PID2
GUID3 PID2
The result of the query would only have PID1 because it has two unique GUID's. PID2 would not be listed has it has the same GUID3 in each row.
Result:
PID1
hi
i have over 200 tables with all same column and data type locate all over the server(20)different database. so i have table call Tname to stored all the link like (databasename.dbo.tablename) so my job will call the Tname table to use cursor to insert records. but the problem is there's one or more table's column name K datatype has been modify by someone else. so is it cause the job fail.
if there a way or SQL statment that i can use Table Tname to see which one is missing column name K? and is there a way i can print out all the datatype and len for all the table column k? please help thanks
Which the column name is the c.Documenttype
here is my T-sql code..
SELECT [Hourly]
,count(case when C.Documenttype=1 THEN '1' END) as EDI
,count(case when C.Documenttype=2 THEN '2' END) as SI
,count(case when C.Documenttype=1 THEN '1' END) + count(case when C.Documenttype=2 THEN '2' END) as GrandTotal
[Code] ....
I am working with a table that has a column which stores multiple data/values that are comma separated.
I need to be able to query that table and get those rows where the values in that column match a pre-defined search list.
I was thinking of somehow trying to take the search list and convert it to a table(temp or a cte) and then JOIN to the table.
however, since the column may contain multiple values, i would need to parse/separate that first. I am not sure how to parse and then join to a list (if that is even the best way to solve this) to only get the rows where the search column contains one or more of the items we're looking for.
Below is some sample data:
Declare @BaseTable table (PKCol int, Column2Search varchar(2000))
Insert into @BaseTable (PKCol, Column2Search)
Select 1001, 'apple,orange,grapefruit'
UNION ALL
Select 1002, 'grapefruit,coconut'
UNION ALL
[Code] ....
I have a multi-column report with a page header that spans the width of the report. Whenever I close the report and reopen it, the header is changed to the width of the column. This isn't a real big deal because I deploy it with the header across the whole page; but once in a blue moon I accidentally hit the F5 key (which I am used to using for refresh in other environments I work in) and the report gets redeployed with the messed up header. Is there anyway to stop RS from automatically adjusting the page header?
And is there anyway to disable the F5 key from deploying the reports. I do use it to build and run windows apps, and don't want to change that, but I don't want to deploy 80+ reports when I accidentially hit it.
Thanks.