Microsoft SQL Server 2008

49K

Solutions

17K

Contributors

Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the  Always On technologies and support for unstructured data types.

Share tech news, updates, or what's on your mind.

Sign up to Post

How can I get better performance with my sql query in a SP? if you look at below my execution pan you will see that :

IF NOT EXISTS(SELECT * FROM Common.[CustomerEntityIds] WHERE EntityType = @EntityType AND CustomerId = @CustomerId)

Open in new window


has alot of memory usage. How  can I reduce that?

ALTER PROCEDURE [Common].[SaveCustomerEntityIds] 
(
	@EntityType	NVARCHAR(128),
	@CustomerId	INT,
	@EntityId	INT OUTPUT
)
AS
BEGIN
	SET NOCOUNT ON;

	IF NOT EXISTS(SELECT * FROM Common.[CustomerEntityIds] WHERE EntityType = @EntityType AND CustomerId = @CustomerId)
	BEGIN
		INSERT INTO Common.[CustomerEntityIds]
					([EntityId]
					,[CustomerId]
					,[EntityType])
				VALUES
					(0
					,@CustomerId
					,@EntityType)
	END

	UPDATE	Common.[CustomerEntityIds]
	SET		[EntityId] = ([EntityId]) + 1
	WHERE	[EntityType] = @EntityType
			AND CustomerId = @CustomerId

	SELECT	@EntityId = EntityId
	FROM	Common.[CustomerEntityIds]
	WHERE	[EntityType] = @EntityType
			AND CustomerId = @CustomerId
END

Open in new window





picture of execution planpicture of execution planExecutionPlan2.sqlplan
0
Learn Ruby Fundamentals
LVL 13
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Hi;

How can I improve performance issue ? I created below stored procedure but if I check costly stored procedure by using sql query to detect them. I realized that below query needs improvement to fix performance issue.Can you help me please?

USE [FFSNext]
GO
/****** Object:  StoredProcedure [WMS].[UpdateQuantityBySalesOrderLineIds]    Script Date: 6/12/2019 11:55:39 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [WMS].[UpdateQuantityBySalesOrderLineIds] 
(
	@SalesOrderLineIds VARCHAR(MAX)
)
AS
BEGIN
	SET NOCOUNT ON;

	UPDATE	PLL
	SET		Quantity = SOL.Quantity
	FROM	WMS.PickListLine PLL

	JOIN	WMS.SalesOrderLine SOL ON SOL.Id = PLL.SalesOrderLineId
	JOIN	PIM.Product SOLP ON SOLP.Id = SOL.ProductId

	WHERE	SOLP.HasAssembly = 0 AND PLL.SalesOrderLineId IN
	(
		SELECT	CAST([value] AS INT)
		FROM	STRING_SPLIT(@SalesOrderLineIds, ',')
	)
	

	UPDATE	PLL
	SET		Quantity = (SOL.Quantity * PLLP.Count)
	FROM	WMS.PickListLine PLL

	JOIN	WMS.SalesOrderLine SOL ON SOL.Id = PLL.SalesOrderLineId
	JOIN	PIM.Product SOLP ON SOLP.Id = SOL.ProductId
	JOIN	PIM.ProductAssembly PLLP ON PLLP.AssemblyProductId = PLL.ProductId

	WHERE	SOLP.HasAssembly = 1 AND PLL.SalesOrderLineId IN
	(
		SELECT	CAST([value] AS INT)
		FROM	STRING_SPLIT(@SalesOrderLineIds, ',')
	)
END

Open in new window

0
This is a related question that Scott helped me with

https://www.experts-exchange.com/questions/29145132/Adding-up-rows.html?headerLink=workspace_answered_questions

And I'm on SQL 2012

I'm running into an issue now that I have more data. You see that #FSS table and Cross Apply? when the #FSS table is empty, I don't get any rows back. I commented that Cross Apply (and fields related to it) and I get rows back.

How can I change it to say... give me rows even if #FSS is empty?
0
Hi guys,
Got a sql server2012 running enterprise evaluation edition.  It’s a free version.
I got license for standard version of 2012 sql

hi i tried to activate through the sql server management studio. entered key and got this error below in pic.. can i ignore that error and go ahead ?
IMG_5639.jpg
or do i need to uninstall enterprise evaluation version.  and install standard version from scratch ? ?
0
Dear Experts,

Are there any housekeeping tips or best practices for an SQL server 2008 R2 (64-bit)?

The server's local hdd of 150GB is full, therefore backup always failed.
0
I have a SQL Server 2008 box that is randomly giving issues with the tempdb file.
At random occurrences the templog file fills up with different transactions executing but then at other times these transactions cause no fill-up.

The only way to bring the templog down when big growth occurs is to manually clear/ kill all open connections / sessions older than two hours that use our front end application that connects to a backend db within SQL Server 2008

tempdb config:
on one drive
 tempdb.....mdf file
 tempdb1....ndf file
 tempdb2...ndf file

templog:
On another drive
templog....ldf file.

Any recommendations?
0
Hi,

Firstly thank you for taking a look at my question.

Say that I have the below queries that are working nicely, but I wanted to put those into a Temp Table or a CTE, so that I can query it, what would be the best way of going about this? Basically I need to do a group by on Area on the below results.

select 'ACT Regional' as [Area] ,count(de_listed_date) as [Num Listed], sum(de_principal) as [$ Listed] ,sum(de_adjustments) as [Adjustments] ,sum(de_paid) as [Paid],sum(case when de_status IN ('PAR','PFP','HAR','PAR','PAD','SOF','PAB') then de_owing else 0.00 END) as [Promised $], sum(case when de_status = 'REC' then 1 else 0 END) as [Recalled #], sum(case when de_status in ('PDF','PLR','SET') then 1 else 0 END) as [Paid & Closed]
from debtor
join client on de_rowid_client = cl_rowid
where de_zip between '2611' and '2620' and cl_number IN ('107','118','117') and de_listed_date > '2016-12-01'
UNION ALL
select 'Adelaide Metro' as [Area] ,count(de_listed_date) as [Num Listed], sum(de_principal) as [$ Listed] ,sum(de_adjustments) as [Adjustments] ,sum(de_paid) as [Paid],sum(case when de_status IN ('PAR','PFP','HAR','PAR','PAD','SOF','PAB') then de_owing else 0.00 END) as [Promised $], sum(case when de_status = 'REC' then 1 else 0 END) as [Recalled #], sum(case when de_status in ('PDF','PLR','SET') then 1 else 0 END) as [Paid & Closed]
from debtor
join client on de_rowid_client = cl_rowid
where de_zip between '5000' and '5199' and cl_number IN ('107','118','117') 

Open in new window

0
hello Guys,

I have a Query that results me 130.000 rows, I need to save all the rows into a txt file.
Today I use my system to do that, row by row and it takes me almost 3 horas processing.
Is there any possibility to have all the rows into a text field, thus I could save all the information
into a file in seconds.

Regards
Alexandre
0
I demoted a 2008r2 domain controller.  Now I cannot log into SQL server.  SQL was installed on this DC because at the time because this was there only server.  Made 2 Manage software runs on this server and the database for this software is installed on SQL.  I didn't realize that this would break SQL.  Anyone know any fix for this?  I won't be back to work until Tuesday to address this, but I an trying to research this now.  Hopefully I will have a fix for this by Tuesday to get our M2M software backup and running.
0
I'm trying to export a View as a Flat text File. The view has 6 months of transactions and executes in 5 seconds.
I created an export data DTS package to export this data to text and it is taking an age, the data file is stored on the same server.

Anyone know why this is taking so long?
0
Angular Fundamentals
LVL 13
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Here is some sample data for a sql server 2014 table


CREATE TABLE #License(
       [customer_id] [int] NULL,
       [license_key1] [nchar](10) NULL,
       [license_state1] [nchar](10) NULL,
       [license_key2] [nchar](10) NULL,
       [license_state2] [nchar](10) NULL,
       [license_key3] [nchar](10) NULL,
       [license_state3] [nchar](10) NULL
 ) ON [PRIMARY]

 INSERT INTO #License
            ([customer_id]
            ,[license_key1]
            ,[license_state1]
            ,[license_key2]
            ,[license_state2]
            ,[license_key3]
            ,[license_state3])
      VALUES
            (11111111
            ,12345    
            ,'IL'
            ,34567    
            ,'IN'
          ,12345    
            ,'IL')

 INSERT INTO #License
            ([customer_id]
            ,[license_key1]
            ,[license_state1]
            ,[license_key2]
            ,[license_state2]
            ,[license_key3]
            ,[license_state3])
      VALUES
            (22222222
            ,66666    
            ,'MI'
            ,999999    
            ,'NY'
          ,87654    
            ,'CO')

 INSERT INTO #License
            ([customer_id]
            ,[license_key1]
            ,[license_state1]
            ,[license_key2]
            ,[license_state2]
            ,[license_key3]
            ,[license_state3])
      VALUES
            (33333333
            ,908763    
            …
0
Hi
What connection string would I use to access my local sql database on my computer. I remember using LocalDB etc
Thanks
0
I have the following stored proc....I am passing @FileData into the from clause....its of type xml ...but the dynamic sql is nvarchar.

how do I format this so that it will use the variable @FileData.

The sql runs fine in a test..only when called as stored proc  I get
Must declare the scalar variable "@fileData".

Here is the stored proc so far.

USE [SharePoint2007Archive]
GO
/****** Object:  StoredProcedure [dbo].[uspCreateAttachments]    Script Date: 5/9/2019 8:49:29 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[uspCreateAttachments]
@ReqID nvarchar(50),
@TableName varchar(MAX),
@xQuery VARCHAR(100),
@fileData XML
AS


BEGIN
Declare @Insert nvarchar(max);

	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
SET NOCOUNT ON;

set @Insert = 'INSERT INTO sharePoint2007Archive.dbo.Attachments (RequestID,Form, Document)
Select '   + QUOTENAME(@ReqID,'''') + ' as RequestID, ' + + QUOTENAME(@TableName,'''') + ' as Form, 
 xData.Col.value(''*:Document[1]'',''nvarchar(max)'') Document
from @fileData.nodes(''' + @xQuery + ''') AS xData(Col)
where DATALENGTH(xData.Col.value(''*:Document[1]'',''nvarChar(MAX)'')) > 0;'
print @Insert;

execute(@Insert);

print 'Inserted New Request ' + @ReqID + 'for Form ' +  @Tablename


END -- uspCreateAttachments

Open in new window

0
This is SQL 2012. I'll go step by step and show what I need done. I'm thinking I need a loop but also somehow to see the next row

1. Sample data
  Create Table #test
(
 Device VARCHAR(250),
 CashCredited Money,
 PlayType VarChar(50),
 DateAndTime DateTime,
 [Transaction ID] BIGINT,
 accunulated money)

--inserts

 INSERT INTO #test
 (
     Device,
     CashCredited,
     PlayType,
     DateAndTime,
     [Transaction ID],
	 accunulated

 )
 SELECT 'MX',-2.50,'Debit','2019-02-05 11:12:21.920',1211793,0 --last column needs to be -2.50


INSERT INTO #test
 (
     Device,
     CashCredited,
     PlayType,
     DateAndTime,
     [Transaction ID],
	 accunulated

 )
 SELECT 'MX', 0,'Credit','2019-02-05 11:12:45.000',1211794,0

 INSERT INTO #test
 (
     Device,
     CashCredited,
     PlayType,
     DateAndTime,
     [Transaction ID],
	 accunulated

 )
 SELECT 'MX', -1,'Debit','2019-02-05 11:30:26.383',1211795,0 -- last column needs to be -3.50

  INSERT INTO #test
 (
     Device,
     CashCredited,
     PlayType,
     DateAndTime,
     [Transaction ID],
	 accunulated
 )
 SELECT 'FSS',0 ,'Posting','2019-02-05 11:30:27.383',8888,0 --second column needs to be 3.50

   INSERT INTO #test
 (
     Device,
     CashCredited,
     PlayType,
     DateAndTime,
     [Transaction ID],
	 accunulated
 )
 SELECT 'MX',0,'credit','2019-02-05 11:31:01.000',1211796,0

    INSERT INTO #test
 (
     Device,
     CashCredited,
     PlayType,
     DateAndTime,
     [Transaction ID],
	 

Open in new window

0
We plan to move from MS SQL 2008 SP4 Enterprise edition to
MS SQL 2016 standard edition :

a) besides exporting out the data/tables & import into the Standard
    Edition, what are the things to watch out for to verify the viability
    to migrate

b) what's the differences that Enterprise offers that Standard doesnt?

c) any other migration checklist items, compatibility & points to note?
0
Dreamweaver 2019 CC
Win 10, 64 Bit, all patches current
Microsoft SQL Server 2008 r2 Express
SSMS installed using window for credentials
Apache installed

Installed is a software I sell and support for the Point of Sale industry.
Use localhost via Chrome to log into a "Back Office" usually used for reports for the end user / customer. I / we also use it for adding items ect.
1. Fully functioning installation.
2. Successfully login via Chrome "localhost" using default user name and password
##
Goal:
Use Dreamweaver to edit webpages display - padding fonts and adjust some of the tabular displays.

Problem:
No matter the page I chose - in Live Mode (NOT LIVE PREVIEW) displays the login page.

Live preview did ask for login - but then displays the page. I'd really prefer to not work in this manner - but if this is the only solution.

Kindly help me out. Thank you.
R/
Vincent.

See my settings below.

Dreamweaver-settings.png
LocalTesting.png
BasicConnection.png
AdvancedConnection.png
ServerChoices.png
0
I am upgrading my SQL server from 2008 r2 to 2012 then to 2016. We have hundreds of Legacy DTS packages that I need to convert to SSIS. In the mean time I was wondering if anyone knows of software or a tool to run Legacy DTS packages in server 2012 or later edition

Thank you
0
Hi,

I am using the Coalesce function to combine records into a comma variable (I'm using SQL 2012) which is then used in another query for the IN query, this is the stored proc.

	@BldID INT
AS

BEGIN

	SET NOCOUNT ON;

DECLARE @listStr VARCHAR(MAX)

-- List all current approvers into a comma value for the IN command
SELECT @listStr = COALESCE(@listStr+',' ,'') + LoginID
FROM tbl_Approvers
WHERE BldID = @BldID

-- Set a dummy value if the returned list is empty
IF (@listStr IS NULL)
   SET @listStr = '-1' 

-- Get available users 
SELECT * FROM [tbl_login] WHERE ([BldID] = @BldID AND UserRole = 'Admin') AND NOT (Id IN (@listStr))

Open in new window


However, this works when only one row in the DB but fails if there are several rows with the following message.

Msg 245, Level 16, State 1, Procedure spTPListApproversAvailable, Line 23
Conversion failed when converting the varchar value '1016,' to data type int.

Open in new window


Any help is appreciated.
0
I want to declare a list:

DECLARE @myList     nvarchar(max)  = '1,2,3~4,5,6';


Do cross appply (or similar) to get:

col 1, col 2, col 3
1         2        3
4         5        6

How would you do that?

/BK
0
Become a Microsoft Certified Solutions Expert
LVL 13
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Hi all,
I'm trying to build a graphs in ssrs report , when I test to receives this report I'm curious why  I can view all  namesgraphs_ssrs_email.PNG which only ssrs present me 3 names  ( managersemail ( those marked as dark ) where the actual  values I should be able to have 100 of them here.

This is how the report looks like in ssrs report builder graphs_ssrs.PNG
0
SQL Server Maintenance

I have a SQL Server that houses a small db for about 20 users. I am by no means a DBA. I am currently using Datto to do image level backups every hour. The server has 2 Drives that are mirror running server 2008 and SQL 2008 and 8 GB of Ram. I would like to know what other tasks i should be doing to make sure the DB is healthy. Also i would like to know if there is a way to monitor its performance to make sure its running at its best.
0
IN SSRS, we have a AD new security group that has users with browser permissions. However when members in this group try to run reports we get this error..

The permissions granted to user 'DOMAIN\testit' are insufficient for performing this operation. (rsAccessDenied)

If we add these same members of the AD group individually with browser permissions, it works fine.  What are we missing on this AD security group?

SSRS is running on SQL2008
0
I'm using sql server 2008.

I have a table that looks like this:

TestTable1.JPG
This is the script to create the table:

USE [TestDatabase]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TestOrders1](
	[OrderID] [int] NOT NULL,
	[LastName1] [varchar](50) NULL,
	[LastName2] [varchar](50) NULL,
	[LastName3] [varchar](50) NULL,
	[LastName4] [varchar](50) NULL,
	[LastName5] [varchar](50) NULL
) ON [PRIMARY]

GO
INSERT [dbo].[TestOrders1] ([OrderID], [LastName1], [LastName2], [LastName3], [LastName4], [LastName5]) VALUES (1, N'Smith', N'', N'Johnson', N'', N'')
INSERT [dbo].[TestOrders1] ([OrderID], [LastName1], [LastName2], [LastName3], [LastName4], [LastName5]) VALUES (2, N'Rogers', N'', N'', N'Taylor', N'Williams')
INSERT [dbo].[TestOrders1] ([OrderID], [LastName1], [LastName2], [LastName3], [LastName4], [LastName5]) VALUES (3, N'Smithers', N'Phillips', N'', N'', N'Lee')
INSERT [dbo].[TestOrders1] ([OrderID], [LastName1], [LastName2], [LastName3], [LastName4], [LastName5]) VALUES (4, N'', N'Jackson', N'', N'', N'Chen')
INSERT [dbo].[TestOrders1] ([OrderID], [LastName1], [LastName2], [LastName3], [LastName4], [LastName5]) VALUES (5, N'Rainier', N'', N'Grisham', N'Jacobs', N'Bly')

Open in new window


I would like to create a column called TestLastnames which is is all the lastname columns seperated by a comma.

My desired result would look like like this column colored in blue:

TestTable1Desired.JPG
What's the best syntax to create this column?
0
Good morning team,

 I have an error (The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.) when trying to sum hours and minutes (duration column) from a table where the column data type is nvarchar(50). I need to aggregate the hours+minutes so I can join on another table to get total work hours for installers out in the field. The select query below will work for specific CustomerName however, I receive the error attached when running for all customers. I've tried at least 10 different ways to resolve but the error is always the same.

As always, thank you all for your time and expertise in helping me get this resolved!

SELECT     TOP (100) PERCENT CustomerName, CONVERT(varchar(10), SUM(DATEDIFF(minute, 0, Duration)) / 60) + '.' + CONVERT(varchar(10), SUM(DATEDIFF(minute, 0,
                      Duration)) % 60) AS install_hours_worked
FROM         dbo.vWIP_Install_TimeSheets AS T
GROUP BY CustomerName


Here is the source query for the view above. This is simply to refine to a list of time sheet entries that meet certain service item criteria (in this case, we're only looking for a WIP report on installation jobs).

SELECT     TOP (100) PERCENT CustomerName, CustomerId, Duration
FROM         dbo.TimeTracking
WHERE     (CustomerName IN
                          (SELECT     Job
                            FROM          dbo.vWIP_Install)) AND (ServiceItemName IN
                          (SELECT     …
0
SELECT        COUNT(Receipt_Detail.Receipt_Number) AS totalcountreceipt, SUM(Receipt_Detail.Amount_Applied) AS receiptamount, Invoice_Header.Invoice_Number,?
FROM            Invoice_Detail INNER JOIN
                         Invoice_Header ON Invoice_Detail.Invoice_Number = Invoice_Header.Invoice_Number INNER JOIN
                         Member_Association ON Invoice_Header.Member_Number = Member_Association.Member_Number INNER JOIN
                         Member ON Invoice_Header.Member_Number = Member.Member_Number INNER JOIN
                         Receipt_Detail ON Invoice_Detail.Invoice_Number = Receipt_Detail.Invoice_Number INNER JOIN
                         Receipt_Header ON Member_Association.Member_Number = Receipt_Header.Member_Number AND Receipt_Detail.Receipt_Number = Receipt_Header.Receipt_Number
WHERE        (Invoice_Detail.Charge_Code = 'D' OR
                         Invoice_Detail.Charge_Code = 'T' OR
                         Invoice_Detail.Charge_Code = 'N')  (Invoice_Header.Invoice_Date BETWEEN '20181201' AND '20190131') AND (Receipt_Header.Deposit_Date BETWEEN 
                         '20181201' AND '20190131')  and (Invoice_Header.Invoice_Amount > 0)
GROUP BY Invoice_Header.Invoice_Number
ORDER BY totalcountreceipt DESC

Open in new window

Inside of "?" if I want to add like below, is it possible? Please show me how.

select top 1 (Receipt_Detail.Amount_Applied) where Receipt_Header.Deposit_Date BETWEEN '20181201' AND '20190131' order by Receipt_Header.Deposit_Date asc
0

Microsoft SQL Server 2008

49K

Solutions

17K

Contributors

Microsoft SQL Server 2008 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. Major improvements include the  Always On technologies and support for unstructured data types.