SQL Server 2008 :: Remove A Value From Union

Jun 23, 2015

I have created a phone list and am using a union to be able to display letter category. However, what I would like to do is only show the letter category if their is an employee with the corresponding last name.

For example, if someone does not have a last name starting with "Z", then "Z" should not show up on my report.

SELECT LastName, FirstName, Dept, Phone
UNION ALL

SELECT v.letter,NULL,NULL,NULL,NULL
FROM (VALUES('A'),('B'),('C'),('D'),('E'),('F'),('G'),('H'),('I'),('J'),('K'),('L'),('M'),('N'),('O'),('P'),('Q'),('R'),('S'),('T'),('U'),('V'),('W'),('X'),('Y'),('Z')) AS v(letter)
ORDER BY vchLastName, vchFirstName

View 9 Replies


ADVERTISEMENT

SQL Server 2008 :: Query To Union Join Data

Jul 30, 2015

I have a query which wants to union join the data. no matter how many times I tried, I got an error. How to change my union query?

select distinct b.lev5 AS "LEVEL 1",b.lev5NAME, C.lev7 "FUND", C.lev7NAME,round (sum(a.data),2) AS AMOUNT
(Select distinct b.lev5
from bf_data a
inner join bf_orgn_cnsl_tbl b
on a.bf_orgn_cd = b.bf_orgn_cd

[Code] .....

View 9 Replies View Related

SQL Server 2008 :: How To Remove Group By Clause

Mar 5, 2015

SELECT DISTINCT

'Banquets - All Day' as revName,
SUM(t.c_items_total) AS Banquet_Total,
SUM(t.cover_count) as Total_Covers,
-- (t.c_items_total) / (t.cover_count) as AvgPer_Cover--

[Code] ....

The output needs to be grouped by the t.c_items_total...I just need the avg per cover (person) / items_total.

View 4 Replies View Related

SQL Server 2008 :: How To Remove Spaces From Output

Jun 23, 2015

When I save my output (from a query I ran) to a text file, there seems to be rows of spaces. Is there a way i can just kill off any spaces at the end of my query? Like rtrim or something?

View 9 Replies View Related

SQL Server 2008 :: How To Remove ENCRYPTED From A FUNCTION

Aug 27, 2015

I have a Table-valued Function already defined in my DB. When I look at it's Properties, it lists Encrypted TRUE.

How can I set Encrypted to FALSE? Is there a t-sql command to ALTER the Function to set Encrypted False?

(fyi, I am syadmin and local admin on this SQL 2008 R2 box)

View 1 Replies View Related

SQL Server 2008 :: Remove Duplicates From Query?

Oct 6, 2015

I am working with a bunch of records that have duplicates on the Persid and the intPercentID where there are duplicates I want to remove when I stick them in the temp table, I tried join on tempo table and doing not exists but still inserts, so now I am trying a merge but same thing. how can I keep duplicates from being inserted in the temp table. I made a cursor as well but its slow as heck, but it does work. trying better ways.

Create table #TempStr (STRId int not null Identity(1,1) primary key, Persid int, percentId int, dtCreated datetime, CreatedBy int)

Create table #NewStr (STRId int, Persid int, percentId int, dtCreated datetime, CreatedBy int)

INSERT #TempStr (Persid, percentId, dtCreated, CreatedBy)
select intPersonnelID, intPercentID, dtSubmitted, intSubmittedBy from tblSTR
whereintpercentId in (61,62) group by intPercentID, intPersonnelID, dtSubmitted, intSubmittedBy
UNION ALL

[code]....

View 3 Replies View Related

SQL Server 2008 :: Remove Double Quote In String Fields

Feb 23, 2015

I have a SQL select syntax as below

0 AS SalaryMin,
2088 AS SalaryMax,
2088 AS BillableHours,
'Month' AS SalaryPaidCode,
0 AS SalaryBreakdownHourly,
0 AS SalaryBreakdownDaily,

[Code] ...

While outputting to CSV.file

I got :0,2088,2088,"Month",0,0,0,0,0,0,0,"N/A","N/A","G","N/A","Exempt","Other",1

How can I remove all double quotes in the string fields? so that O can get the result as below while the output
0,2088,2088,Month,0,0,0,0,0,0,0,N/A,N/A,G,N/A,Exempt,Other,1

View 7 Replies View Related

SQL Server 2008 :: Single Script To Remove Secondary Log Files

Mar 18, 2015

I am new to SQL and I haven't written any scripts in the past. I thought I would give it a go. Basically, I am trying to write a script that will check if a database has more than one log files, free the VLFs that belong to the secondary log files and then remove them. I created a database named rDb as this link suggests and followed the steps.

[URL] ....

It works. However, I want to have to run just 1 script that will do the entire job. This is what I have gotten so far and it doesn't work:

create table #tempsysdatabase(
File_id int,
file_guid varchar(50),
type_desc varchar (20),
data_space_id int,
name nvarchar (50),
state int,

[Code] ....

View 0 Replies View Related

SQL Server 2008 :: How To Remove / Uninstall Management Data Warehouse

Aug 12, 2010

I have tried to set up the Management Data Warehouse on one of our production servers, but it is not working (not collecting any data) so I want to completely remove it and try the installation again. There does not seem to be any remove/uninstall option.

How to completely remove the Management Data Warehouse?

Version:
Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (X64)
Mar 29 2009 10:11:52
Copyright (c) 1988-2008 Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7600: )

View 7 Replies View Related

SQL Server 2008 :: Remove Rows Affected From Query In Send Mail

May 6, 2015

I need to remove "rows affected" text from results as shown below from posted Sp. I am using set nocount on but its not working as expected.

Create Procedure DailyCheckList
As
SET NOCOUNT ON
Declare @EmailSub varchar(500),@dt varchar(100),@Msg varchar(max),@M varchar(max)
set @dt= convert(varchar(20),GETDATE(),107)

[Code].....

View 1 Replies View Related

Duplicates Again! UNION Join - Remove Records With Column Diff.

Sep 9, 2004

Hello All,

We all were new at one point.... any help is appreciated.

Objective:

Combining two 49,000 row tables and remove records where there is only 1 column difference. (keeping the specified column value removing the one with a blank.)

Reason:

I have 2 people going through a list, coding a specific column with a single letter value. They both have different progress on each sheet. Hence I am trying to UNION them and have a result of their combined efforts without duplicates.

My progress/where I'm stuck:

Here is my first query/union:

SELECT * FROM [Eds table]
UNION SELECT * FROM [Vickis table];

As shown above, I have unioned these 2 tables and my results removed th obvious whole record duplicates, but since 1 column is different on these, a union without criteria considers them unique.....

an example of duplicates that I must remove are as follows:

142301 - Product 5000 - 150# - S (Keep)
142031 - Product 5000 - 150# - "" <--- Blank (Remove)

I am trying to run another query on my first query results so I don't mess my first query up. Here it is:

SELECT DISTINCT [Prod #], [Prod Name], [Prod Description], [Product Type]
FROM [Combined Tables]
WHERE [Product Type]<>" ";


Please Help! Thank you in advance.

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

5 minutes away from pulling my last one!

BaldNAskewed

View 7 Replies View Related

SQL Server 2008 :: Normalizing Data Prior To Migration (Update String To Remove Special Characters)

Aug 21, 2015

I'm presented with a problem where I have a database table which must be migrated via a "custom tool", moving the data into a new table which has special character requirements that didn't exist in the source database. My data resides in an SQL Server 2008R2 instance.

I envision a one-time query which will loop through selected records and replace the offending characters with --, however I'm having trouble understanding how this works.

There are roughly 2500 records which meet the criteria of "contains bad characters", frequently containing multiple separate bad chars, and the table contains roughly 100000 rows.

Special Characters are defined as #%&*:<>?/{}|~ and ..

While the field is called "Filename" it isn't always so, it is a parent/child table where foldernames are also stored.

Example data:
Tablename = Items
ItemID Filename ListID
1 Badfile<2015>.docx 15
2 Goodfile.docx 15
3 MoreBad#.docx 15
4 Dog&Cat#17.pdf 15
5 John's "Special" Folder 16

The examples I'm finding are all oriented around SELECT statements, to change the output of what I see returned, however I'd rather just fix the entire column using an UPDATE. Initial testing using REPLACE fails because I don't always have a single character as the bad thing in a string.

In a better solution, I found an example using a User Defined Function to modify the output of a select, but I cannot use that UDF in an UPDATE.

My alternative is to learn enough C# to modify the "migration tool" to do this in-transit, but I know even less about C# than I do of SQL.

I gather I want to use @@ROWCOUNT to loop through the rows but I really can't put it all together in a cohesive way.

View 3 Replies View Related

2008 Installed; Can I Remove 2005?

Apr 7, 2008



I have 2008 installed and have 'smoke tested' it (tried it on the several projects and don't appear to have any show stopper type issues). Anyways, I'd really like to remove VS 2005 if at all possible. My concern is what effect removing that is going to have one the following other installs:

SQL Server 2005 Express
SQL Management Studio (Enterprise NOT Express)
.NET Framework v2.0

If anyone can weight in on the effect uninstalling 2005 is going to have, or ways to 'safely' uninstall it without affecting any of the other installs, please let me know...

Thanks,

View 1 Replies View Related

How Does Union/union All Work Inside SQL Server?

Apr 29, 2008



Why the sequence different?



select * from (

select id=3,[name]='Z'

union all select 1,'G'

union all select 2,'R'

union all select 4,'Z'

) as t

order by [name]

--result:

---------

--1 G

--2 R

--4 Z

--3 Z

select * from (

select id=3,[name]='Z'

union select 1,'G'

union all select 2,'R'

union all select 4,'Z'

) as t

order by [name]

--result:

----------

--1 G

--2 R

--3 Z--changed

--4 Z

View 3 Replies View Related

SQL 2012 :: Remove Clustering On Windows 2008 R2

Oct 16, 2014

How to remove clustering configuration in windows server 2008 r2 after it shows clustering events as critical and status down...

View 1 Replies View Related

Cast/Conv Expression Remove The Slash : 02/02/2008

Mar 27, 2008

Hi, I need help please.

I have text source & i need to write it to table field being an integer.
I complains about the column, so i added a derived column but I am clueless in the expression:

Source from text: 02/02/2008
Derived column expression to output: 20080202 in a int datatype

I need the expression to do it.

Please Assist!

Regards

View 13 Replies View Related

SQL Server Management Studio: Can Not Remove AdventureWorksDB In Add Or Remove Programs Of Control Panel

Nov 30, 2006

Hi all,

I tried to remove AdventureWorksDB in the "Add or Remove Programs" of Contol Panel and I got the following errors: (1) AdventureWorksDB     Error 1326: Error getting file security: CProgram FilesMicrosoft SQL ServerMSSQL1MSSQLGetLastError: 5.      |OK|   and (2) Add or Remove Programs   Fatal Error during installation (after I clicked the |OK| button).   Please help and tell me how I can solve this problem.

Thanks in advance,

Scott  Chang 

View 1 Replies View Related

How Do I Clean Up The SQL Server (ctp) From ADD/REMOVE Program Without The Change/remove Button

Oct 12, 2006

I have uninstalled the CTP version of the SQL Server express so that I can install the released version but CTP version is still listed in the add/remove program list but without the change/remove button. I have been to different sites to find information on cleaning this up and I have ran all the uninstall tool I can find but the problem still prevails. I cannot install the released version without completely getting rid of the CTP version. Please help anyone.

Thanks

deebeez1

View 1 Replies View Related

Reporting Services :: How To Remove Duplicate Rows In SSRS 2008

Dec 21, 2011

I have a dataset in my report that pulls 10 fields. One of the tablixes on report should display only 8 of the 10 fields and this is causing the duplicate records to show up on the tablix.I tried hide duplicates option for the entire details row and have set the scope to "Details". It did not work. I am getting the data from a stored procedure and cannot do much on that.

View 7 Replies View Related

Integration Services :: 2008 - Script Task Break Points Not Removed When Choose To Remove All In Package

Jun 11, 2015

On the main BIDS menubar, there is a menu for Debug.  If I select Debug > Delete All Breakpoints, any breakpoint in a script task is still there afterwards.  Is there a way other than opening the script task and removing it there?

View 3 Replies View Related

T-SQL (SS2K8) :: Using Union ALL Or Union Kills Performance On Stored Proc

Jun 12, 2014

SQL Server 2008 r2...

I have a query which does 3 selects and Union ALLs each to get a final result set. The performance is unacceptable - takes around a minute to run. If I remove the Union All so that the result sets are returned individually it returns all 3 from the query in around 6 seconds (acceptable performance).

Any way to join the result sets together without using Union All.

Each result set has exactly the same structure returned...

Query below [for reference]...

WITH cte AS (
SELECT A.[PoleID], ISNULL(B.[IsSpanClear], 0) AS [IsSpanClear], B.[SurveyDate], ROW_NUMBER() OVER (PARTITION BY A.[PoleID] ORDER BY B.[SurveyDate] DESC) rownum
FROM[UT_Pole] A
LEFT OUTER JOIN [UT_Surveyed_Pole] B ON A.[PoleID] = B.[PoleID]

[Code] .....

View 4 Replies View Related

Can I Run SQL Server 2008 - Reporting Services CTP Until Microsoft Sells SQL 2008

Mar 31, 2008

There are a few features in the new SQL Server - Reporting Services that I really need in production. I have tested everything and it works great. I am running the CTP version since Microsoft is saying they aren't releasing the release version until 3rd quarter 2008.


Since Microsoft won't sell SQL 2008 until 3rd quarter, can I run the CTP in production until the release and then purchase SQL 2008?


Jim

View 1 Replies View Related

Seeking Advice: SQL Server On Win 2008 Virtual Server Or Just Win 2008?

Apr 23, 2008



Hello - does anyone have experience w/SQL Server 2005 in a virtual environment? I'm considering this for a production environment but not sure if performance will suffer. Our databases will have a lot of writing but not too much reading. A SSRS solution is currently the only app. connecting to the SQL db. Max users to server at any given time will be very low (~10 users max). But the databases are pulling in data from other, outside multiple data sources on a daily basis.

Any pointers to documentation or any advice?

Thanks,

A Brown

View 1 Replies View Related

Problem With Windows Server 2008 And SQL 2008 Express

Feb 25, 2008

Hello!
Recently, I set up server with Windows Web Server 2008 RC1, SQL 2008 Express beta, .NET 3.5, IIS 7.
I'm running ASP.NET web application with SQL database. Everything works fine until the first application state on the server expires. After that, any postback that starts a new application state on the server and connects to the database, results in the following error:
Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.
Is this a bug that will be fixed in release of Windows / SQL or am I doing something wrong?
Many thanks for help,
Jan

View 1 Replies View Related

Unable To Remove SQL Instance In Add/Remove Program

Mar 8, 2007

I need help,

I am having a hard time removing my SQL instance inside the Add/Remove program. After i select the SQL Instance name and then I tried to remove it but it won't allow me to delete it. There isn't any error message or whatsoever. Actually, when i try to log it in my SQL Management studio, that certain sql instance name is not existing according to the message box. Is there any way to remove the Sql Instance in my system?

I appreciate your help, Thanks

IS Support

View 1 Replies View Related

Microsoft SQL Server 2008 CTP, February 2008

Mar 7, 2008




Hi all,



New to this so please be patient and please help.



I have developed an SQL 2005 Express command line option install for our company which has been working seamlessly for the last 18 months.

http://msdn2.microsoft.com/en-us/library/ms144259.aspx

I downloaded the €œMicrosoft SQL Server 2008 Express CTP, February 2008€? from http://www.microsoft.com/downloads/details.aspx?FamilyId=749BD760-F404-4D45-9AC0-D7F1B3ED1053&displaylang=en



I simply replaced the 2005 file €œSQLEXPR.EXE€? with the 2008 file €œ€?, recompiled the installation and tested only for it to fail. I than read the 2008 books online and noted the change in command line options.

http://www.microsoft.com/downloads/details.aspx?familyid=19DB0B42-A5B2-456F-9C5C-F295CDD58D7A&displaylang=en

http://msdn2.microsoft.com/en-us/library/ms144259(SQL.100).aspx

I then changed the command line to suit the Microsoft 2008 books online, recompiled the installation and tested only for it to fail once more.



Interestingly I tested the install from the default GUI and at the point of adding the €œsa€? login credentials it fails to allow the installation to proceed. Strangely by selecting the windows authentication credentials, €œnext€? than €œback€? it now allows me to add the €œsa€? login credentials and continues to install correctly as required.



I hope I have explained this clearly enough.


1. Is this a bug in the €œMicrosoft SQL Server 2008 CTP, February 2008€? installation?
2. If so is this causing the command line install options to fail?
3. How do I obtain a version of €œMicrosoft SQL Server 2008 Express€? that will work installing from the command line?





Thanks in advance.


View 1 Replies View Related

PB Using UNION ALL With VB6 And SQL-server

Mar 29, 2004

I'm working on a softwear and I have to create some Update. This softwear used first MS Access as a database, and now I have to create the code which allows it to use MS SQL-server. This softwear is created in VB6.

I've got some error when I'm using the UNION ALL function. This error appears:
"incorrect syntax towards the key word ' union' "

Here is the code in VB6 :

" GOpenLocalDb (FOR_READ) ' open the database

SQLStmt = "select * from ol_table_temp"
SQLStmt = SQLStmt & " where [Subject_no] = " & dlr_subject & " "
ord$ = SQL_Order()
SQLStmt = SQLStmt & ord$

'dalafouzos: 24/09/2002 I added the lines below to include the DLR entries in the ol_old table
SQLStmt = SQLStmt & " union all select * from ol_table_old where [Subject_no] = " & dlr_subject & " "
ord$ = SQL_Order()
SQLStmt = SQLStmt & ord$

'GOpenLocalDb (FOR_READ) ' open the database
Set DLRset = New ADODB.Recordset
DLRset.CursorLocation = adUseClient
DLRset.Open SQLStmt, g_objConn, adOpenKeyset, adLockReadOnly, adCmdText "

when the error appears the value of SQLStmt is :

"select * from ol_table_temp where [Subject_no] = 1020 Order by [Date] DESC, [Time] DESC union all select * from ol_table_old where [Subject_no] = 1020 Order by [Date] DESC, [Time] DESC "

Thanks for your help...

View 2 Replies View Related

UNION / INTERSECT / EXCEPT In SQL Server 2000

Sep 21, 2006

Hi,I'm coming back to Sql Server after 4 years away, using other RDBMS,and there's a few things I'm struggling to remember how to do (if Icould do them in the first place...)Main amongst those is EXCEPT syntax.In DB2, if I have two sets of data and I want to exclude the second setfrom the first, I can do:SELECT col1, col2, col3, ... colNFROM table1EXCEPTSELECT col1, col2, col3, ... colNFROM table2;But SQL Server balks at this. I've had a quick look in the T-SQL helpfor EXCEPT, but I didn't find that particularly enlightening. Anypointers as to how I should be doing this?ThanksJames

View 5 Replies View Related

Linked Server SQL UNION ALL Problem

Apr 12, 2008

Hi-

I'm importing an Excel spreadsheet into SQL Server using the spreadsheet as a linked server. I've written the following query to do so:

Use TESTDB
go

SELECT * INTO VTAble FROM LINKSER...[DIST1$]
UNION ALL
SELECT * FROM LINKSER...[DIST2$]
UNION ALL
SELECT * FROM LINKSER...[DIST3$]
UNION ALL
SELECT * FROM LINKSER...[DIST4$]
UNION ALL
SELECT * FROM LINKSER...[DIST5$]
UNION ALL
SELECT * FROM LINKSER...[DIST6$]
UNION ALL
SELECT * FROM LINKSER...[DIST7$]

.... and it continues for 28 tables.

The spreadsheet tables are suposed to be identical, however I receive this error:


Msg 205, Level 16, State 1, Line 2

All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.

I'm guessing that in a couple places in the spreadsheet their is some variance in the data. I've experimented with running the query without SELECT statements for certain tables and have identified that there is something wrong with those tables. Is there a more systematic way I can locate the spreadsheet errors?

View 5 Replies View Related

Union All Does Not Union All Rows

Nov 6, 2006

Hi all,

I have a Union All transformation with 4 inputs and one output when I debug the package the sum of the different inputs rows does not match the row count in output.

I don't understand, I've used the Union All transform many times and I've never seen this.

Any idea why this could happen ?

View 18 Replies View Related

UNION Statement That Works In SQL Server But Not Access

Nov 29, 2006



Hi,

Is there a way I can get this select Union statement to work in Access.

SELECT '' AS Router UNION SELECT DISTINCT Router FROM IPVPNRouterUpgradeCharges WHERE SchemeID = 12 AND

Router <> 'IPVPN Lite' AND Router <> 'VPN Bridge'

AND Router <> 'IPVPN Aggregated Bandwidth' ORDER By Router

I get this message in Access: Query input must contain at least input of query

Thanks for any help

Chris

View 1 Replies View Related

SQL Server 2014 :: Union All Statement Hangs Engine?

Sep 9, 2014

I have TSQL query using UNION ALL. First subset returns 92 rows, second subset return 0 (ZERO) rows. Now if I execute them separately they execute subsecond. If I put UNION ALL between them then it hangs forever exactly on 88s row.

I understand I need to provide execution plans, actual queries etc but before going into all this details, why on earth even in theory UNION ALL with empty result will result in a hang of the first subset?

Based on estimated execution plan 2 subqueries are performed in parallel and then CONCATENTION is being used which shall result with just first subset immediately displayed in result.

Estimated execution plan attached, I can not get actual execution plan because query never completes.

View 9 Replies View Related

SQL Server 2014 :: UNION ALL In View With Temp Table

May 8, 2015

I have a performance issue with one of the views when I join the view with a temp table

I have 2 Views - View1 and View2.

There is a third view - view_UNION where the

view_UNION =
SELECT * FROM View1
UNION ALL
SELECT * FROM View2

If I have a query like -

Select view_UNION.* FROM
view_UNION INNER JOIN #TMP ON #TMP.ID = view_UNION.ID

the execution is too slow.

But if I execute the views separately, I get good performance.

How to improve the performance of the view_Union

View 7 Replies View Related







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