Transact SQL :: How To Align Records From Two Columns Into One

Sep 3, 2015

How do I align output from two columns into a single column? Below are the DDL/DML as required with sample data.

CREATE TABLE #Users(
UserID VARCHAR(7),
G1 VARCHAR(30),
G2 VARCHAR(30),
G3 VARCHAR(30),

[code]....

View 5 Replies


ADVERTISEMENT

Transact SQL :: Select And Parse Json Data From 2 Columns Into Multiple Columns In A Table?

Apr 29, 2015

I have a business need to create a report by query data from a MS SQL 2008 database and display the result to the users on a web page. The report initially has 6 columns of data and 2 out of 6 have JSON data so the users request to have those 2 JSON columns parse into 15 additional columns (first JSON column has 8 key/value pairs and the second JSON column has 7 key/value pairs). Here what I have done so far:

I found a table value function (fnSplitJson2) from this link [URL]. Using this function I can parse a column of JSON data into a table. So when I use the function above against the first column (with JSON data) in my query (with CROSS APPLY) I got the right data back the but I got 8 additional rows of each of the row in my table. The reason for this side effect is because the function returned a table of 8 row (8 key/value pairs) for each json string data that it parsed.

1. First question: How do I modify my current query (see below) so that for each row in my table i got back one row with 19 columns.

SELECT A.ITEM1,A.ITEM2,A.ITEM3,A.ITEM4, B.*
FROM PRODUCT A
CROSS APPLY fnSplitJson2(A.ITEM5,NULL) B

If updated my query (see below) and call the function twice within the CROSS APPLY clause I got this error: "The multi-part identifier "A.ITEM6" could be be bound.

2. My second question: How to i get around this error?

SELECT A.ITEM1,A.ITEM2,A.ITEM3,A.ITEM4, B.*, C.*
FROM PRODUCT A
CROSS APPLY fnSplitJson2(A.ITEM5,NULL) B,  fnSplitJson2(A.ITEM6,NULL) C

I am using Microsoft SQL Server 2008 R2 version. Windows 7 desktop.

View 14 Replies View Related

SAN, Diskpart And Align=64

Jul 19, 2007

When creating a new disk partition for SQL Server on a SAN (RAID 5) do you use Diskpart with the Align= parm to keep from doing two physical I/O operations for each logical I/O?



Do you use Align=64?



All comments welcome...TIA



DeWayne



View 5 Replies View Related

Right Align Dollar Signs

Jun 4, 2007

Hello Everyone,




Does anyone know where I can go to get the format to make

$ right align + =Sum(Fields!Blah.Blah) as #,###.00?



|------------------------------|

|$ 23.00|

|$ 1,000.00|

|------------------------------|



I can not figure out how to get the dollars to right align like Excel ?



Please point me to the answer or a previous post that answers this...



View 4 Replies View Related

IIF Expression In Text Align Property

Oct 30, 2007



I have run into what appears to be a strange bug (or I am expecting too much) in SQL Reporting Services.

I have a field with a dollar amount. If the dollar amount = 0, then the users want "NA" to display. I have this set-up correctly.

I have now found that if the dollar amount is displayed, they want the text box right aligned, and if the "NA" is displayed, then they want the text box to be center aligned.

I put the following expression in the "TextAlign" property setting...




Code Block
=IIF(Field.value = 0, Center, Right)


Now the IIF function is available in my expression window, and so is "Center" and "Right". But when I try to run the report, I get the error that "Center" is not declared.

So maybe this just is not possible in SQL Reporting Services, but I wanted to check before I told the users "no can do".

BTW, I tried "Left", "Right", and "General" in place of "Center" and got the same error.

Thank you,

T.J.

View 5 Replies View Related

How To Right Align A Text Column In SQL Server?

Dec 3, 2007



Hi guys,

I need to right align some text in a varchar column (arabic text)!!!
Any clues, hints?
HELP PLEASE!

Yousef

View 5 Replies View Related

Reporting Services :: Left And Right Align In Same TextBox?

May 19, 2015

I have an Expression with two different Texts. I would life for the Left part to be Left Aligned and the Right Part be Right Aligned.

Region 5
Region 2 7

However I can only use spaces and it shows up like this

Region         5
Region2         7

It counts the number of spaces between the first text and second. I want it to be normalized so I figured left and right align. I have tried placeholders but the placeholders only accept 1 align. When i change the second placeholder alignment it also changes the first alignment.

View 3 Replies View Related

Transact SQL :: Retrieve All Records From Parent Table And Any Records From Child Table

Oct 21, 2015

I am trying to write a query that will retrieve all students of a particular class and also any rows in HomeworkLogLine if they exist (but return null if there is no row). I thought this should be a relatively simple LEFT join but I've tried every possible combination of joins but it's not working.

SELECT
Student.StudentSurname + ', ' + Student.StudentForename AS Fullname,
HomeworkLogLine.HomeworkLogLineTimestamp,
HomeworkLog.HomeworkLogDescription,
ROW_NUMBER() OVER (PARTITION BY HomeworkLogLine.HomeworkLogLineStudentID ORDER BY

[Code] ...

It's only returning two rows (the students where they have a row in the HomeworkLogLine table). 

View 3 Replies View Related

Query Analyzer. Align/indent Stored Procedure Script

Jul 23, 2005

Hi,Is there a way to align/indent the stored procedure script ( like VBAAdd-Ins Smart Indenter )Thanks, Eugene

View 2 Replies View Related

How To Align The Text In Justify Format With SQL Server Reporting Services?

Jan 18, 2007



How to align the text in justify format In SQL server Reporting Services? Is there any code to do so?

View 29 Replies View Related

SSRS Report Designer Background Image Does NOT Align With Text In Preview

Sep 12, 2007

Hi,


I'm using the SSRS report designer within VS2005 and I have a .rdl report that I have placed a background form as an image background. I then have text placed on top of the form, the problem is that everything is aligned within the report designer layout view but when I go to view the report in report preview the text no longer remains vertically aligned within the background form.


This is very frustrating, and almost makes it impossible to marry up a form with report data. Any help would be appreciated.

View 5 Replies View Related

Transact SQL :: Get Sum Of Records Per Day

Oct 28, 2015

I have a big table which has fields(ID, RecordDate, Value). The records were 15 minutes interval, start at yyyy-mm-dd 00:00:00 and end at yyyy-mm-dd 23:45:00 for each day. Some records may be missing.how can I do the query:if the every 15 min records exists in the day, do sum(value) for the day
else do something else.I would like see difference between SQL 2008 and 2012.

View 8 Replies View Related

Transact SQL :: How To Sum Records In Series

Dec 3, 2015

I have the following store procedure which list a certain amount of product

SELECT P.Name, P.ProductCode, P.Quantity, P.ItemUnitWeight, P.Weight, P.WeightUnitMeasureID, P.IsDeleted, UNIT.UnitMeasureCode, P.StoreID, dbo.v_ProductItemWeight.TotalWeight,
dbo.v_ProductItemWeight.UsedWeight, Production.ProductCategory.Name AS CategoryName, Production.ProductCategory.ProductCategoryID, Production.ProductItem.Quantity AS UnitQuantity,
Production.ProductItem.UsedQuantity
FROM Production.Product AS P INNER JOIN

[Code] ....

This store procedure produce the following result set :

Result Set

From the result set above, in fact what I need to get is a single records for each ProductCode and adding 2 fiels which are the Sum(UNitQuantity) and the Sum(UsedQuantity)

How can I add those 2 field in my querry and group it by ProductCode ?

View 13 Replies View Related

Transact SQL :: Getting Min And Max Records From Join

Oct 1, 2015

I have 2 tables:

create table #InsuredLoc (
PolGK int,
InsuredLocGK varchar(20),
InsuredLocEffDt datetime,
InsuredLocType varchar(20),
InsuredLocStatus varchar(20),
InsuredLocAddress varchar(50),
PolEdrGk varchar(20),

[Code] ...

I will need to join the #InsuredLoc table to the #PolicyEndorsement table using PolGk and PolEdrGk and get the min(BkgDt) and min(PolEdrRowUpdateDt) for the distinct list of InsuredLocType, InsuredLocStatus, and InsuredLocAddress fields from the #InsuredLoc table above.

 I will also need the min(InsuredLocEffDt) and the max(InsuredLocUpdateDt) from the #InsuredLoc table for those records. So after the first run, i should get the following:

I tried to use CTE's with ranking, but some records are dropping off and I'm not sure why.  

View 6 Replies View Related

Transact SQL :: Top 10 Columns In All The Tables

Oct 21, 2015

In our production database we are looking top 10 columns in all the tables, for this using the below script, output was showing only one table how we get the all the tables top 10 ...

select top 10 * from ProductIdList

View 6 Replies View Related

Transact SQL :: Missing Records In One Tables

Oct 11, 2015

I want to know one small query..

id Name
1 hi
2 how
3 are
4 you
6 can
7 do
8 not
9 did 
10 to 

I deleted some records now my table have below mentioned rows..

id Name
1 hi
2 how
4 you
6 can
8 not
10 to 

I want to know  the missing records in my table.

OUTPUT IS. 3,7,9

how can  i do that using sql query.

View 11 Replies View Related

Transact SQL :: Records Returned To Same Status

Jul 23, 2015

In my database I have an Audit table, that keeps track of teams worked upon the same record in a workflow.I need to find out how many records have been returned to the first team for correction ?The column 'Status' is numbered from 1 to 6 and Column 'EditTime' saves the time when record has been edited.how many records have been returned for correction and identify those records.

View 9 Replies View Related

Transact SQL :: Trigger Did Not Fire For Few Records

Jun 1, 2015

 IF OBJECT_ID('dbo.AuditLog','U') IS NULL BEGIN
CREATE TABLE [dbo].[AuditLog]

[code]....

[AuditLogId] [bigint] IDENTITY(1,1) NOT NULL,
[DateCreated] [datetime] NOT NULL,
[TableName] [nvarchar](200) NULL,

i have the Audit_log table and the trigger above on Account table..it is working fine and i have some 1000 records in Audit log table  , but it did not fire for some customers and i found trigger did not fire for 60 plus customers any possible reasons ??? that trigger did not fire ? Below are the timings account have been created but trigger did not log them 

2015-04-29 10:22:08.243
2015-04-29 11:01:49.150
2015-04-29 11:08:16.617
2015-04-29 11:40:34.407

[code]...

View 17 Replies View Related

Transact SQL :: Loading Records In Batch?

Sep 2, 2015

I have a stored procedure that attempts to INSERT @BatchSize number of records at a time into a table. Currently, I have @BatchSize set to load 50,000 at a time. The table I am inserting from has a little over 67,000 records. 

When I execute the procedure with NOCOUNT left off, the procedure seems to run indefinitely, and the count of records returned surpasses what I have in the source table. However, only 50,000 records are inserted into the table.

Below is my code:

begin try

--error catching variables:

declare @Error_NumberLocal int
,@Error_MessageLocal varchar(4000)
,@Error_SeverityLocal int
,@Error_StateLocal int
,@Error_ProcedureLocal varchar(200)
,@Error_LineLocal int
,@User_NameLocal varchar(200)

[code]....

What is the problem with the looping structure that would cause this issue?

View 6 Replies View Related

Transact SQL :: Show Particular Records Within Same Group?

Aug 13, 2015

I have a table with 5 columns, let say ID,PersionID, Date, Type,Qty  and source data looks like this

ID   PersonID    Date            Type       Qty  

1      1        01/01/2011       Accept      5          
2      1        01/01/2011       Accept      5  
3      2        02/01/2010       Accept      10             
4      2        02/01/2010       Deny        20  
5      3        02/01/2012       Accept      15

[Code] .....

Output should look like this..look for only Type=Accept until deny is reached. After Deny,if there is a Accept ignore it.

ID  PersonID    Date            Type         Qty
1    1        01/01/2011       Accept        5      (show only one Accept row=1 becoz Type is Accept and date is same,Qtyis
same)
3    2        02/01/2010       Accept        10     (show Accept row=3,ignore deny row)

5    3        02/01/2012       Accept        15     (show Accept row=5)

6    4        05/05/2012       Accept        25     (show Accept rows=6,7 and ignore Deny & Accept rows = 8,9)

7    4        07/08/2012       Accept        20
        
11   6        01/01/2011       Accept        5      (show Accept rows=11,12 because Qty is different)  

12   6        01/01/2011       Accept        15

Create Sample Table (ID int null, PersonID Int null, Date Datetime null , Type varchar(10) null, Qty int null)

Insert into sample values (1 ,1,'01/01/2011','Accept',5),

(2,1,'01/01/2011','Accept',5),  
(3,2,'02/01/2010','Accept',10),             
(4,2,'02/01/2010','Deny',20),  
(5,3,'02/01/2012','Accept',15),  
(6,4,'05/05/2012','Accept',25),  
(7,4,'07/08/2012','Accept',20), 
(8,4,'07/08/2012','Deny',5),
(9,4,'09/23/2012','Accept',23),
(10,5,'09/08/2012','Deny',12),
(11,6,'01/01/2011','Accept',5),          
(12,6,'01/01/2011','Accept',15)

View 4 Replies View Related

Transact SQL :: Paging Of Records Which Are Keep Updating

May 7, 2015

I would like to use the following code for querying summary records with paging.

DECLARE @PageNumber AS INT, @RowspPage AS INT
SET @PageNumber = 1
SET @RowspPage = 10
SELECT * FROM (
SELECT ROW_NUMBER() OVER(ORDER BY create_date) AS NUMBER,
* FROM summary
) AS TBL
WHERE NUMBER BETWEEN ((@PageNumber - 1) * @RowspPage + 1) AND (@PageNumber * @RowspPage)
ORDER BY create_date

Paging is implemented for fast response since the data pool is very large up to 10000000.

The above query works fine in testing. However, in reality, since new records are keep inserting to the tables, I have concern about the accuracy of viewing another page of result.

E.g.  At 12:00pm, the result of page 1 (5 per page)  is
R20, R19, R18, R17, R16

After 2 mins, 12:02pm, the user press next page button
Since records R21, R22, R23, R24, R25, R26 are inserted
page 2 result would be R21, R20, R19, R18, R17

So the result is showing many records same as page 1 which has already been seen. Could this situation be improved?

View 2 Replies View Related

Transact SQL :: How To Get Missing Records From One Table

Apr 22, 2015

I have one table with many records in the table. Each time a record is entered the date the record was entered is also saved in the table. I need a query that will find all the missing records in the table. So if I have in my table:

ID          Date          Location
1           4/1/2015        bld1
2           4/2/2015        bld1
3           4/4/2015        bld1

I want to run a query like

Select Date, Location FROM [table] WHERE (Date Between '4/1/2015' and '4/4/2015') and (Location = bld1)
WHERE Date not in
(Select Date, Location FROM [table])

And the results would be:

4/3/2015   bld1

View 17 Replies View Related

Transact SQL :: How To UPDATE More Than 500 Records In One Call

Aug 13, 2015

I have following query which is created dynamically as -

UPDATE  BUILDTABLE  SET BUILD_ID =  '984137'  WHERE SET_NUMBER = '1889147436' AND SEND_DATE = '1941-03-04'; 
UPDATE  BUILDTABLE  SET BUILD_ID =  '984137'  WHERE SET_NUMBER = '1115509374' AND SEND_DATE = '1991-09-01'; 
UPDATE  BUILDTABLE  SET BUILD_ID =  '984137'  WHERE SET_NUMBER = '1515579671' AND SEND_DATE = '1941-05-24'; 
UPDATE  BUILDTABLE  SET BUILD_ID =  '984137'  WHERE SET_NUMBER = '1795509670' AND SEND_DATE = '1958-01-14';
UPDATE  BUILDTABLE  SET BUILD_ID =  '984137'  WHERE SET_NUMBER = '1915508672' AND SEND_DATE = '1961-09-07';

Here till " UPDATE BUILDTABLE SET BUILD_ID =  '984137'" is the same clause for all queries, but "where" condition is different for all queries. I have to update more than 500 UPDATE statements(like above) in one call. Currently I am concatenating all the queries in string Builder which is time consuming.I want to increase performance of application.Any other class like BulkCopy ?

View 18 Replies View Related

Transact SQL :: Records Inserted Missing

Apr 25, 2015

Am witnessing a very strange issue when i try to insert some records . I get the message in the SSMS  like 5,10 etc rows affected. When i check for the same records in the table none of them is present.

This problem then automatically goes away after some time and all get backs to normal. I only have the access to that database no other user have the access. Totally confused about the all of a sudden new behavior of the database.

View 10 Replies View Related

Transact SQL :: Count Weeks With More Than Two Records

Aug 22, 2015

My table is test and I have an ID and DateTest columns

I would like to count the weeks with more then one record.

So far I got this and return the weeks with 1 record per week. How can I count the weeks with more then one record

select sum(c)
from (
select c = count( id) over (partition by id, datepart(week, DateTest))
from test where id = '1' and DateTest >= '7-7-2015'
) a where c = 1

View 11 Replies View Related

Transact SQL :: Display Records According To Date

Oct 2, 2015

I have a table that have student names and their birth dates just like below

a) tblStudentInfo

which shows records like below (Birth Dates are shown in Year-Month-Day format)

ID   StudentName        BirthDate   
1     ABC                       2002-12-25 
2     DEF                        2002-09-10  
3     GHI                        2002-09-19 
4     JKL                        2002-06-10 

[code]...

I want to perform a query that should display the upcoming birthday of all students according to today.Lets say, today is 2015-10-02, so the query should display the result according to today's date just like below

ID   StudentName        BirthDate   
1     ABC                       2002-12-25 
2     VWX                      2002-01-01
3     STU                        2002-02-03 
4     PQR                     2002-03-05 

[code]...

View 3 Replies View Related

Transact SQL :: Find Duration From Two Records

Oct 26, 2015

I am working on one logic. I have a table as below.

Declare @Table table (ID int, StartDate datetime, EndDate datetime)
Insert Into @Table (ID, StartDate, EndDate)
Values (1, '2013-01-01', '2013-12-31') 
, (1, '2014-01-01', '2014-06-30') 
, (2, '2014-01-01', '2014-07-31') 
, (2, '2014-08-02', '2014-08-30') 
select * from @Table 

I need as below.

ID, StartDate, EndDate
1, '2013-01-01', '2014-06-30'
2, '2014-01-01', '2014-07-31'
2, '2014-08-02', '2014-08-30'

Means If ID is same for two or more than two records then difference between first row's EndDate and second row's StartDate is 1 day then we should get one record as output. How can we built this logic in T-SQL ?

View 12 Replies View Related

Transact SQL :: Comparing Records Between Two Tables

Sep 29, 2015

I need to compare records between two tables. There is no ID in the tables to do a simple join between them. So, what I'm looking for is: get the first record from table1 and read all record from table2 and give me back the most similar record. The String Distance is a predefined function.

Select a.table1
,b.table2
from table1 a, table2 b
where StringDistance (''a.table1,'b.table2') >90

View 4 Replies View Related

Transact SQL :: Update All Records In Table?

Oct 22, 2015

Every day the timestamp is changed on all rows in one of the table(table has 1 mio records).

What is the best way to find out which query is doing this?

Could be also query which updates only one record(or couple of them) but is executed for each record once.

I have been looking sys.dm_exec_query_stats and sys.dm_exec_sql_text for past but couldn't find.

I can't use event notifications since there is service broker disabled.

View 5 Replies View Related

Query Help, What Columns For All Records Are Empty

Aug 30, 2004

I am wanting to make a query to find out if there are any columns in a table that are null for all records.

So far I am using a cursor that holds all the column names of that table and then a stored procedure that would use a loop to cycle through all the column names in a query to essentially count the number of nulls for each column and then an If statement to check to see if the #of nulls = to the number of records.

What isn't working is my query to count the number of nulls...Here is my query

select count(*)
from XYZ
where @cName is null

Ive tried declaring cName as a sysname, and varchar, neither work.

Also, I've tried using COL_NAME(OBJECT_ID('XYZ'), someColumnIndx)...I think this would be the better choice just because I wouldn't need to use a cursor, but both aren't working.
I am a bit new to MSSQL and don't know my way around the system tables. Is there a sys table that would give me this info so I wouldn't need to perform a query?

Any info would be great.

View 4 Replies View Related

Delete Records When You Have A Primary Key Of Two Columns

Jun 12, 2006

Hi everyone.

I have two tables: the catalog table and the detail table.
The two tables are joined by a two-columns key.

I want to make a Delete sentence for delete all the rows in the Catalog table that aren't in the detail table, in SQL Server.

The only problem is that the key is composed by two colums.

If the Key was maded of one column, that would be easy, like this:

DELETE FROM CATALOG
WHERE CATALOGKEY NOT IN (SELECT CATALOGKEY FROM DETAIL)

But it is possible to make a delete sentence if the key has two columns ?


Thanks

View 2 Replies View Related

Duplicate Records In Multiple Columns.

May 21, 2008

Hello,

I have a question regarding duplicate records, the thing is I'm able to query for duplicated records if I type the following:


select ColumnName from TableName
where ColumnName in
(
select ColumnName from TableName
group by ColumnName having count(*) > 1
)


That gives me duplicate records for one column, but I need find duplicate records in more than one column (4 columns to be exact), but the way I need to find these records is they all have to be duplicate, what I'm trying to say is I don't don't want to find the following:

First Last Age Email
John Smith 25 jsmith@hotmail.com
John Smith 26 jsmith@hotmail.com
John Smith 25 jsmith4@hotmail.com

I need to find the following:

First Last Age Email
John Smith 25 jsmith@hotmail.com
John Smith 25 jsmith@hotmail.com
John Smith 25 jsmith@hotmail.com

So all the columns must be exactly the same, that's the only condition I want to show the records, is there any way to do this?

For the record, I'm using MS SQL Server 2000, thank you.

View 12 Replies View Related

Converting Multiple Records Into Columns

Oct 11, 2013

I have a table called DISTRIBUTION_SL in which there will multiple records for each request as shown below in the data.I would like to convert the recepient email into columns and then join with other tables so that the entire request information is seen in one row rathar than multiple rows

Table
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CREATE TABLE [dbo].[DISTRIBUTION_SL](
[requestid] [numeric](18, 0) NOT NULL,
[rptdis] [char](1) NOT NULL,
[recipnm] [varchar](50) NULL,
[emailadr] [varchar](75) NULL,

[code]....

View 6 Replies View Related







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