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

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
Active Protection takes the fight to cryptojacking
LVL 2
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

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
rrrplease take a look of the attached file. It is a simple invoice to receipt (1 to m) relationship. and my question is.

1. assume I give you receipt received to date range 01/01/2019 to 01/14/2019. how can get the following in SQL query.

Invoice ID Total Receipt Count Receipt Amount
1                 25.00              1
2                 0                      0
3                 0                      0
0
Hello,

I have a SQL Replication problem. I added some tables in an existing replication and I don't know what tables they are. Is there any way to see the history of tables I have added? (SQL 2008 R2)

I hope u can help me!
JN
0
Hello,
In current Production environment hosted on Microsoft SQL Server 2008, we have expensive sql query that is killing the database. We wish to add additional index to existing table.
SQL Query. This database is currently monitored by Solar wind and it has recommended to add index to the existing table. This table has currently 20 million records.

SELECT PVT_CHG_LOG_SEQ,  
   "Table_Name",  
   PK_Column_Name,  
   PK_Value,  
   ADP_SYNC_REQ_FLAG,  
   SYNC_STATUS,  
   SIBL_SYNC_STATUS,  
   ADP_SYNC_STATUS,  
   PRIORITY,  
   RETRY_COUNT,  
   SIBL_RESPONSEDESC,  
   ADP_RESPONSEDESC,  
   SIBL_COMPL_TIME,  
   ADP_COMPL_TIME,  
   Created_Date,  
   9,1  
FROM dbo.INT_PVT_DATA_CHANGE_LOG  
WITH  
   (
      UPDLOCK,  
      NOWAIT
   )  
WHERE (SYNC_STATUS = @P0)  
ORDER BY 9,1 ASC  

Recommendation from Solar wind to add inded
Clustered Index Scan (OBJECT:([CPMSPROD].[dbo].[INT_PVT_DATA_CHANGE_LOG].[PK__INT_PVT___61283AF276F68FE1]), WHERE:(CONVERT_IMPLICIT(nchar(1),[CPMSPROD].[dbo].[INT_PVT_DATA_CHANGE_LOG].[SYNC_STATUS],0)=[@P0]))

Question: a) Do we need to create new clustered or non clustered index for column SYNC_STATUS  to the table INT_PVT_DATA_CHANGE_LOG or modify existing index PK__INT_PVT___61283AF276F68FE1 to incorpate the column SYNC_STATUS

b) Any other guidelines to be followed while adding index

Regards
Tom
0
CEOs need to know what they should worry about
CEOs need to know what they should worry about

Nearly every week during the past few years has featured a headline about the latest data breach, malware attack, ransomware demand, or unrecoverable corporate data loss. Those stories are frequently followed by news that the CEOs at those companies were forced to resign.

In my SSIS for each loop...
It is grabbing each file in the folder and running the processes
Then moving the file just completed into an archive folder
My problem is that it is running the processes nN times depending on number of files remaining

So... if I start with 8 files...
It inserts the first file 8 times and runs the processes that many times
Moves that file
And then does the next file 7 times
And so in

Any ideas?

SSIS
For Each Loop Properties
0
I’m using sql server.

I have a table that has a lastname,firstname and middleinitial columns.
They are these datatypes:

[LastName] VARCHAR(30)
[FirstName] VARCHAR(20)
[MidInit] VARCHAR(1)

So when I run this query

SELECT [LastName],[FirstName],[MidInit]
FROM [Emplyoees]

I get this:

LastName FirstName MidInit
Simpson    Homer       J
Simpson    Lisa            M
Bunny        Bugs
Bonney      William      H

I would like to create a column called FullName that displays the data in this format LastName, FirstName MidInit

So then the new column would like like this:

FullName
Simpson, Homer J
Simpson, Lisa M
Bunny, Bugs
Bonney, William H

What’s the beat syntax to create this column?

Notice how bugs bunny has no MidInit.
When employee has no MidInit don’t place any character in the string for the middleinit.
1
creating Indexes to boost query performance

Please provide me some examples where indexes and clustered indexes would help to boost performance of a database query.

Thanks
0
I could really use some of your expertize with this query.

I need to turn this Select query to an Update.

Need to  Update table Itemsite and field CycleId for every Invtid returned by this select statement:

declare @today char(10)
declare @month char(2)
declare @day char(2)
declare @year char(4)

set @month=DATEPART(month, GETDATE())
set @day=DATEPART(day, GETDATE())
set @year=DATEPART(year, GETDATE())
set @today=rtrim(@month)+'/'+rtrim(@day)+'/'+rtrim(@year)



SELECT top (5)percent
b.INVTID,
a.cycleid,
a.LastCountDate,
COUNT(b.INVTID) AS TICKETS

from itemsite a,soshipline b,soshipheader c
where c.CpnyID = b.CpnyID and c.ShipperID = b.ShipperID
and b.invtid=a.invtid and c.SiteID=a.siteid and
            c.CpnyID ='0001' AND
            c.CustID LIKE '%' AND
            c.CustID <> 'AAA1000' AND
            c.Status ='C' AND
            c.SiteID LIKE 'WEST' AND
            DATEDIFF(day, c.OrdDate, @today)<=280 and
            c.sotypeid<>'tr' AND
            c.cancelled<>'1' and
            left(b.InvtID,3) in ('g/h','WHI','FRI')

      GROUP BY b.INVTID,a.lastcost,a.LastCountDate,a.CycleID
      ORDER BY a.LastCountDate asc,TICKETS desc,b.INVTID
0
Please provide a list of SQL Database Objects

I am curious about whether "SQL Database Objects" makes you think of scripts, stored procedures, functions, views and triggers. Or, if there is a set of objects I may have not worked with yet.

Please confirm that those which I listed are in fact "SQL Database Objects" or list any that come to mind.

Thanks.
0
Problem: Update query with "SET" utilizing an Aggregate Function

Wondering if you would be so kind as to assist me with formatting this query the property way.

Here is the Select Query:


SELECT     zzz_po_OpenPurchOrd.InvtID, SUM(zzz_po_OpenPurchOrd.QtyPending) AS QtyPendPO, ItemSite.QtyOnPO, ItemSite.SiteID
FROM         zzz_po_OpenPurchOrd LEFT OUTER JOIN
                      ItemSite ON zzz_po_OpenPurchOrd.InvtID = ItemSite.InvtID
WHERE     (zzz_po_OpenPurchOrd.InvtID like 'googsx%')
GROUP BY zzz_po_OpenPurchOrd.InvtID, ItemSite.QtyOnPO, ItemSite.SiteID
HAVING      (ItemSite.SiteID = 'WEST') and SUM(zzz_po_OpenPurchOrd.QtyPending) <>ItemSite.QtyOnPO

Open in new window


--the query below comes from converting a Select into an Update Query in Designer
--the goal is to updates the Itemsite.QtyonPO to actual pending Purchase order quantities (QtyPendPO --this is the calculation on the above select Query)


UPDATE    ItemSite
SET              QtyOnPO =SUM(zzz_po_OpenPurchOrd.QtyPending)
FROM         zzz_po_OpenPurchOrd LEFT OUTER JOIN
                      ItemSite ON zzz_po_OpenPurchOrd.InvtID = ItemSite.InvtID
WHERE     (zzz_po_OpenPurchOrd.InvtID LIKE 'googsx%') AND (ItemSite.SiteID = 'WEST') AND (zzz_po_OpenPurchOrd.QtyPending <> ItemSite.QtyOnPO)

Open in new window


Here is the error returned:
Msg 157, Level 15, State 1, Line 2
An aggregate may not appear in the set list of an UPDATE statement.
0
I need to migrate a server running Windows 2008 and SQL 2008 to Windows 2012 and SQL 2012.  What is the best approach?
0
Hi,
i got a windows 10 pro 64 bit desktop.
for some reason. windows update is not working,

i tried . - windows troubleshooting within windows
windows update troubleshooter
did check disk
did sfc/scan
deleted software distribution folder. restarted windows update service.
 but still its giving same error.  attached a pic of the error.

main reason i want update to work is - i need .netframework 2.0 from turn on feautres. when i try to enable .netframework2.0 it tries to download from windows update.

if my update does not work .  any other way to install .netframework2.0 ???
update.PNG
0
Hi,

In current production environment, we have requirement to truncate approx 860 million records from table in MS SQL server 2008. Please advise the best option to truncate table without impacting end users within production environment.


Regards
Tom
0
Fundamentals of JavaScript
LVL 13
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

I am getting an error message
Error Executing Database Query. [Macromedia][SQLServer JDBC Driver][SQLServer]Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

I do know where the problem is but do not know how to correct the issue.

      
                DECLARE @userKey INT
                SET @userKey = 71963

                DECLARE @Dob   datetime
                SELECT  @Dob= (select dateOfBirth from users where userKey = 71963)
           
            SELECT top 1 F.sessionKey,F.locationKey,F.locationkeylist,F.officeStateKey,F.sessionStart,F.sessionEnd,F.locationName,F.address1,F.address2,F.city,F.state,F.zip,F.gender,F.badgeNum,
			F.seatCount,F.seats,F.availSeats,F.btwScheduleThreshold,F.availStateCode,F.repost,F.ConflictIn,F.ConflictIn2,F.buddyHoldIn,F.firstname,F.lastname,F.searcherAge,F.age,F.multiLoc
            FROM
            (
            	SELECT T.*,
                case WHEN T.availSeats = 1 THEN
                    (SELECT (CONVERT(int, CONVERT(varchar, T.sessionStart, 112)) - CONVERT(int, CONVERT(varchar, U.dateOfBirth, 112)))/10000 FROM users U inner join sessionMap SM2 on SM2.userKey = U.userKey WHERE SM2.sessionKey = T.sessionKey)
                    WHEN T.repost = 1 THEN
                    (SELECT (CONVERT(int, CONVERT(varchar, T.sessionStart, 112)) - CONVERT(int, CONVERT(varchar, U.dateOfBirth, 112)))/10000 FROM users U inner join 

Open in new window

0
I have two numbers in separate columns in my sql view. One is just the number of minutes and the other is the number of seconds. How can I combine these into one value that shows mm:ss? I tried just doing [Mins] + ':' + [Seconds] but if the seconds are 0 then it looks like this: 2:0. I need it to look like this: 2:00. How can I do this?
0
Hi,

Thank you experts for taking a look at my question.

Basically I have the below stored proc I am trying to create, The query itself works, but for some reason it is not letting my create a stored proc.

Could you please help me work out why?

USE [cv_masterdb]
GO

/****** Object:  StoredProcedure [dbo].[spdatereturn]    Script Date: 15/02/2019 10:37:03 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[spmonthdiffnew]
	-- Add the parameters for the stored procedure here
	@monthfrom date,
	@monthto date
	
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;
    -- Insert statements for procedure here
--DECLARE @firstDayOfListedMonth DATE = CONVERT(DATE, DATEADD(DAY, -DAY(GETDATE()) + 1, DATEADD(MONTH, - @monthsBack, GETDATE())));
--DECLARE @lastDayOfListedMonth DATE = CONVERT(DATE, DATEADD(DAY, -DAY(GETDATE()), DATEADD(MONTH, - @monthsBack + 1, GETDATE())));

select case when  DATEPART(DAY, @monthfrom) <=  DATEPART(DAY, @monthto) 
    then datediff(month, @monthfrom, @monthto)  
    else datediff(month, @monthfrom, @monthto) -1  
    END
GO

Open in new window


Basically it is a stored proc to return back the number of months in between 2 given dates.

many thanks for your help!
0
In the function below...

I am building a #temp table that will have from 20k - 5k records in it
I am then doing a select on that table

Select * from #temp
WHERE 1 = 1
      AND dbo.brkOwnsTimeshareContract(ISNULL(b.ExternalID2, '0')) = 1;

Open in new window


It seems slow... and I am wondering if I have a better solution or tweak on either my select or the underlying function itself

The dbo.everyware_t_contract table generally has @ 60k records in it

ALTER FUNCTION [dbo].[brkOwnsTimeshareContract]
    (
        @OwnerID INT = NULL
    )
RETURNS TINYINT
AS
    BEGIN

        DECLARE @OwnerBucket TINYINT = 0;

        IF EXISTS (   SELECT ContractID
                      FROM   dbo.everyware_t_contract c
                      WHERE  c.OwnerID = @OwnerID
                             AND (   c.ContractStatus = 'Active'
                                     OR CHARINDEX('Phase', c.ContractStatus) > 0
                                     OR CHARINDEX('Pender', c.ContractStatus) > 0 
									 OR CHARINDEX('Suspense', c.ContractStatus) > 0 
									 OR CHARINDEX('Not Back', c.ContractStatus) > 0 
									 OR CHARINDEX('Presale', c.ContractStatus) > 0 )
                             AND NOT (   CHARINDEX('club', c.ContractType) > 0
                                         OR CHARINDEX('guest', c.ContractType) > 0
                                         OR CHARINDEX('goc co', c.ContractType) > 0
                                         OR CHARINDEX('goc breck', 

Open in new window

0
Hi Experts,

Thank you for taking the time to take a look at my question - your help is very much appreciated and is invaluable!

basically I want to create a stored procedure, that will return 2 dates.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE datereturn
	-- Add the parameters for the stored procedure here
	<@monthsback int>
	
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
DECLARE @firstDayOfListedMonth DATE = CONVERT(DATE, DATEADD(DAY, -DAY(GETDATE()) + 1, DATEADD(MONTH, - @monthsBack, GETDATE())));
DECLARE @lastDayOfListedMonth DATE = CONVERT(DATE, DATEADD(DAY, -DAY(GETDATE()), DATEADD(MONTH, - @monthsBack + 1, GETDATE())));
END
GO

Open in new window


Should I just create a temptable that writes the 2 dates to a field and then do a select * from temptable ? if that is the case could you please help with that part?
0
At this link:

https://stackoverflow.com/questions/92082/add-a-column-with-a-default-value-to-an-existing-table-in-sql-server


I saw this example that works fine. It adds a column to the table and sets the default value of every row in that column to 1.

ALTER TABLE Protocols
ADD ProtocolTypeID int NOT NULL DEFAULT(1)
GO

Is there a way to write this line in two statements?
ADD ProtocolTypeID int NOT NULL DEFAULT(1)


So with the first statement add the column.
then with a separate statement set the default value to 1
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.