Quantcast
Channel: Latest Questions on SQL Server Q&A from the SQL Server Central community
Viewing all 11276 articles
Browse latest View live

Hemp become frequently utilized

$
0
0

sera labs cbd oil review Hemp become frequently utilized for the sails and cord of ships which made it a obligatory crop for early American colonies and settlements even finally locating its way into the US Army and US Department of Agriculture's Hemp for Victory marketing campaign which substantially aided in World War 2 efforts. Hemp's makes use of are so giant it become experimented with by way of Henry Ford whilst inventing the contemporary automobile and now plays a function in foreign vehicle maker BMW's attempt to make cars recyclable and extra environmentally friendly. Hemp even finds its way into some of the bird seed you locate on the puppy shops.


How to count number of items in a specific type in a table in sql?

$
0
0

I have a table named Movie, with actors attribute.

actors_type is specific and looks like this:

ACTOR_TYPE is implemented as a varray(5) of varchar(20)

GEORGE.ACTOR_TYPE('Clint Eastwood', 'Christopher Carley', 'Bee Vang', 'Ahney Her')

the query I tried to count the number of movies for each actor is :

select m.title, a.column_value, count(m.title) 
    from movie m, table(m.actors) a  
    group by m.title,  a.column_value 
    order by a.COLUMN_VALUE

which gives me a count of each row(?) Not the count of movies for each actor. the output is as below:

what I am trying to get is to List actors that acted in multiple movies and show movie title and the actor. but when I add m.title in the select statement, it will count each row. This is the other query I wrote:

select a.column_value, count(m.title)  
    from movie m, table(m.actors) a  
    having count(m.title) > 1 
    group by a.column_value  
    order by a.COLUMN_VALUE 

which gives me a table of COLUMN_VALUE that is a actor name and count of movies acted in, which is 2.

these are correct but I need to add the title to the output too, but when I add it, all the counts will be one, as the first output table.

There is no table for Actors, we create table for it via `table(m.actors) a` to access its items.

Is performance of Outer Apply of table valued functions sequence dependent?

$
0
0

We have recently had an update on our production system and performance in certain areas has degraded by a factor of 50. I am trying to get a handle on this and made the following observation..

I have reports that are realised as table valued in-line functions,.These call subordinate table valued inline functions that each generate a single line based on a passed parameter from the outermost query. I found that under some circumstances, I could return to previous performance levels by reordering the OUTER APPLY sequence of the subordinate functions.

I have never seen this behaviour previously and have two questions.

1. Is this something that should happen at all?

2. If it's not generally seen, what might this be indicating (indexing?),

The subordinate functions when called individually perform well.

Thanks for any advice,

Stan

Merge Replication error between SQL 2008 R2 publisher & SQL 2012 Subscriber

$
0
0

Hi

I have tried to configure merge replication between Publisher with SQL 2008 R2 Standard and Subscriber with SQL 2012 standard. Tried configuring with distributor on SQL 2012.

While configuring the subscriber I was unable to configure through SQL 2012 SSMS. So I have configured through SQL scripts.

After configuration Synchronization is not running, Sanpshot was ran successfully. But Merger synchronization is showing error as,"The SQL Server version of the Publisher server needs to be upgraded to 'Microsoft SQL Server 2012'. (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147200956)"

In my current environment we can't upgrade the publisher to SQL 2012.

So, please help me.

Thanks

Merge Replication error between SQL 2008 R2 publisher & SQL 2012 Subscriber

$
0
0

Hi

I have tried to configure merge replication between Publisher with SQL 2008 R2 Standard and Subscriber with SQL 2012 standard. Tried configuring with distributor on SQL 2012.

While configuring the subscriber I was unable to configure through SQL 2012 SSMS. So I have configured through SQL scripts.

After configuration Synchronization is not running, Sanpshot was ran successfully. But Merger synchronization is showing error as,"The SQL Server version of the Publisher server needs to be upgraded to 'Microsoft SQL Server 2012'. (Source: MSSQL_REPL, Error number: MSSQL_REPL-2147200956)"

In my current environment we can't upgrade the publisher to SQL 2012.

So, please help me.

Thanks

Issue while using like operator with regex expression

$
0
0

Hi All,

I am facing issue while using like operator with regex expression.

Below is the sample SQL script

create table #Temp (displayname varchar(100) )

insert into #Temp values('SG_UNFE_01_VIPCP30DY')

select * from #Temp where displayname like '%^[A-Z][A-Z]_[A-Z][A-Z]FE_[0-9][0-9]_VIP.*%'

drop table #Temp

Please help, Thanks in advance.

How to restrict managers from viewing employees data that do not report to them from a SSRS report

$
0
0

I have created a report in SSRS when a manager is selected from a drop down managers list of parameter, it displays data of all employees that report to this manager. However, currently, any manager can select any other manager from the list and be able to see data of all employees that report to the selected manager. I want to restrict managers so managers can only view records of employees that they manage. Users use windows login to access the reports.

Your insight will be greatly appreciated.

Using WHERE in a CAST Query

$
0
0

Hi all, I am just wondering if anyone can please help with the following issue;

I have the following Query which runs fine, but, I need to add a WHERE filter and just can't get it to work? I am totally new to this and any help would be really appreciated. Thank you.

	SELECT Name, 
       Description,
       IsEnabled, 
       ExternalAuthProviderName,
       ExternalUserName, 
       Email, 
       CAST(XmlData AS XML).value('UserDetail[1]/Text1[1]', 'varchar(255)') AS "SummaryGroup",
       CAST(XmlData AS XML).value('UserDetail[1]/Text2[1]', 'varchar(255)') AS "SecurityGroup",
       CAST(XmlData AS XML).value('UserDetail[1]/Text3[1]', 'varchar(255)') AS "Access",
       CAST(XmlData AS XML).value('UserDetail[1]/Text4[1]', 'varchar(255)') AS "InsiderList" 
	FROM SecUser 
	WHERE   ???????? 
	ORDER BY Name

SS Report Builder 2016 Parameter Difficulty

$
0
0

I am building a report in SS Report Builder 2016 and need to grant users the ability to sort the report by Vendor Names, which is a column from my second dataset. Both datasets are using embedded queries, from different servers, that I do not have the ability to link.

Need result for below

$
0
0

I have 2 tables

I need SQL query for the above result

How to Use TSQL to Query JSON String into its Component Parts?

$
0
0

Hi there,

I have 3 tables (JsonPage, JsonSection, JsonControl) into which I would like to split and store JSON strings relationally. Using tsql how do I query the JSON string to split it into its page, section, and control parts?

TIA

unpivot a sql (columns to rows)

$
0
0

I have a table with 7 columns and I am trying to unpivot to rows.

All the Columns starting P1Start should be a new column in new Unpivoted table.

Table should like sample_Unpivot table : P1Start,P1End,P2Start,P2End ... should be a row value .

I have attached the insert script below.

Can you please provide me the code ?

CREATE TABLE [dbo].[sample](
 [id] [int] NULL,
 [P1StartOrderDate] [datetime] NULL,
 [P1StartReceiveDate] [datetime] NULL,
 [P1EndOrderDate] [datetime] NULL,
 [P1EndReceiveDate] [datetime] NULL,
 [P2StartOrderDate] [datetime] NULL,
 [P2StartReceiveDate] [datetime] NULL,
 [P2EndOrderDate] [datetime] NULL,
 [P2EndReceiveDate] [datetime] NULL
) 
CREATE TABLE [dbo].[sample_unpivot](
 [id] [int] NULL,
 [Phase] [char](30) NULL,
 [OrderDate] [datetime] NULL,
 [ReceiveDate] [datetime] NULL
)  
INSERT [dbo].[sample] ([id], [P1StartOrderDate], [P1StartReceiveDate], [P1EndOrderDate], [P1EndReceiveDate], [P2StartOrderDate], [P2StartReceiveDate], [P2EndOrderDate], [P2EndReceiveDate]) VALUES (1, CAST(N'2020-01-01 00:00:00.000' AS DateTime), CAST(N'2020-01-03 00:00:00.000' AS DateTime), CAST(N'2020-05-01 00:00:00.000' AS DateTime), CAST(N'2010-01-01 00:00:00.000' AS DateTime), CAST(N'2020-08-01 00:00:00.000' AS DateTime), CAST(N'2020-01-11 00:00:00.000' AS DateTime), CAST(N'2020-05-03 00:00:00.000' AS DateTime), CAST(N'2020-01-04 00:00:00.000' AS DateTime))
GO
INSERT [dbo].[sample_unpivot] ([id], [Phase], [OrderDate], [ReceiveDate]) VALUES (1, N'P1Start  ', CAST(N'2020-01-01 00:00:00.000' AS DateTime), CAST(N'2020-01-03 00:00:00.000' AS DateTime))
GO
INSERT [dbo].[sample_unpivot] ([id], [Phase], [OrderDate], [ReceiveDate]) VALUES (1, N'P1End  ', CAST(N'2020-05-01 00:00:00.000' AS DateTime), CAST(N'2020-01-01 00:00:00.000' AS DateTime))
GO
INSERT [dbo].[sample_unpivot] ([id], [Phase], [OrderDate], [ReceiveDate]) VALUES (1, N'P2Start  ', CAST(N'2020-08-01 00:00:00.000' AS DateTime), CAST(N'2020-01-11 00:00:00.000' AS DateTime))
GO
INSERT [dbo].[sample_unpivot] ([id], [Phase], [OrderDate], [ReceiveDate]) VALUES (1, N'P2End  ', CAST(N'2020-05-03 00:00:00.000' AS DateTime), CAST(N'2020-01-04 00:00:00.000' AS DateTime))
GO

does it make sense to grant databaseroles in tempdb to a user?

$
0
0

I discovered some users have database roles on tempdb but is it useful? According to MS "any user can create temporary objects in tempdb" Are these permissions ignored? Some users have a deny_datareader role.

I have a powershell script below that imports data from a filepath to a table in sql server management studio. It runs painfully slow. Is there anyway that is recommended to speed it up?

$
0
0

$insert=@'

INSERT INTO FileAuthor(FilePath, FileAuthor)

VALUES ('{0}','{1}')

'@

$FolderPath="\\INSERT File path HERE\*"

$connectionString='Data Source=CBYLAW1HCX093\NetDocs;Initial Catalog=ND_Cokinos;Integrated Security=SSPI'

$conn=New-ObjectSystem.Data.SqlClient.SqlConnection($connectionString)

$conn.Open()

$cmd=$conn.CreateCommand()

Get-ChildItem$FolderPath|Get-ChildItem-recurse-file|% {

# Retrieves File Author

$folderObj= (New-Object-ComObjectShell.Application).namespace((Split-Path-Path$_.FullName))

$fileAuthor=$folderObj.getDetailsOf($folderObj.items().item($_.Name),20)

#Gather metadata and write to SQL

$FilePath=$_.FullName -replace"'","''"

$cmd.CommandText =$insert-f$FilePath,$fileAuthor

$cmd.ExecuteNonQuery()

}

Getting 'the network path was not found' error while downloading excel file from SharePoint site in SSIS.

$
0
0

Getting 'the network path was not found' error while downloading excel file from SharePoint site in SSIS 2012. It works fine if the file is accessed manually in browser before execution of the script task. The HTTP connection manager successfully connects to the SharePoint file.


Multiples values from xml document not extracted

$
0
0

When shredding an XML document, I came across the situation where multiple values in the XML document was not extracted when I specified the path at a higher level, but it did when I specified using the specific node.

To give some clarity to what I am saying, Consider XML document of this format:

DECLARE @Document XML;


DECLARE @Test TABLE (

ID INT NOT NULL,

XMLData XML NOT NULL);


SET @Document = '<MyData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

<Root>

<Level1>

<Level2 id ="A">

<Level3 id ="A" AffiliationRefs ="A">

<Level4>A</Level4>

<Level4>B</Level4>

</Level3>

</Level2>

</Level1>

</Root>

</MyData>';


INSERT INTO @Test

(ID, XMLData)

VALUES

(1, @Document);

I am trying to extract the 2 values A and B from <Level4>

When I specified the value in the below format mp.Level3.value('(./Level4)[1] (which is at a higher level), the values did not shred.

WITH Test1CTE

AS (

SELECT a.ID, w1.Level2.value('@id','VARCHAR(50)') PPID,

mp.Level3.value('(./Level4)[1]','VARCHAR(250)') Code

FROM @Test a CROSS APPLY a.XMLData.nodes('./MyData/Root/Level1/Level2') AS w1(Level2)

CROSS APPLY w1.Level2.nodes('Level3') AS mp(Level3))


SELECT * FROM Test1CTE;

But when I pointed using the specific node pd.Level4.value('(.)[1]', it shred and gave 2 rows:

WITH Test2CTE

AS (

SELECT a.ID, w1.Level2.value('@id','VARCHAR(50)') PPID,

pd.Level4.value('(.)[1]','VARCHAR(250)') Code

FROM @Test a CROSS APPLY a.XMLData.nodes('./MyData/Root/Level1/Level2') AS w1(Level2)

CROSS APPLY w1.Level2.nodes('Level3') AS mp(Level3)

CROSS APPLY mp.Level3.nodes('Level4') AS pd(Level4))


SELECT * FROM Test2CTE;

Can anyone help me understand why this is happens?

Why is the .bak file from Sql Server 2014 is bigger in size as compared to .bak file from Sql Server 2008 for same database

$
0
0

Hi,

I have taken backup of a database from Sql Server 2014 and found that the size of the backup file is bigger as compared to the size of backup taken from Sql Server 2008 of same database.

difference is quite significant, can anyone guide me for the same.

Regards.

https://evaherbalist.com/patroxidan/

$
0
0

patroxidan review Does your dog look to move a bit slower this present day? Does it nearly look like he would prefer to lie around rather than exit and trap the ball? Lots of instances, our pets endure from arthritis identical to we do and many people deal with our dog's ache within the identical manner that we would deal with ours; we give them a pain reliever. The article is that dogs don't have the identical make up as we do, so what perhaps innocent for us would be possibly deadly for them. When you consider that we love our dogs, we do not wish to see them hurting, but it surely's important to prefer the proper sort of joint agony remedy for dogs that will offer them no terrible side effects and get their mobility back up.

https://evaherbalist.com/patroxidan/

It is SQLZOO Problem. I have got 3 solutions please advice for the best solution. If there is any better solution I will be thankful.

$
0
0
  • Examples:
  • Capital Monaco-Ville the name is Monaco and the extension is -Ville.
  • Capital Guatemala City the name is Guatemala and the extension is City.
  • Show the name and the extension where the capital is an extension of name of the country.
  • Solutions:
  • 1.
  • Select name, Right(capital,Length(capital)-Length(name))
  • From world
  • Where capital like concat(name,'%') and name<>capital;
  • 2.
  • Select name, Substring(capital, length(name)+1)
  • From world
  • Where capital like concat(name,'%') and name<>capital
  • 3.
  • Select name, replace(capital,name,'')
  • From world
  • Where capital like concat(name,'%') and name<>capital;

How do I loop through a date range and count only the weekdays?

$
0
0

I tested with the following code which wasn't successful:

while (@datetest1 < @datetest2) begin if datepart(d,@datetest1) = 1 set @datetest1 = dateadd(d, 1, @datetest1) if datepart(d,@datetest1) = 2 set @counter = @counter + 1 set @datetest1 = dateadd(d, 1, @datetest1) if datepart(d,@datetest1) = 3 set @counter = @counter + 1 set @datetest1 = dateadd(d, 1, @datetest1) if datepart(d,@datetest1) = 4 set @counter = @counter + 1 set @datetest1 = dateadd(d, 1, @datetest1) if datepart(d,@datetest1) = 5 set @counter = @counter + 1 set @datetest1 = dateadd(d, 1, @datetest1) if datepart(d,@datetest1) = 6 set @counter = @counter + 1 set @datetest1 = dateadd(d, 1, @datetest1) if datepart(d,@datetest1) = 7 set @datetest1 = dateadd(d, 1, @datetest1) end

Viewing all 11276 articles
Browse latest View live