[Solved] why the stored procedure not work and showbox “incorrect syntax near ‘)’. ” [closed]

You have a surplus comma here: @answer nvarchar (100)=null, ) also checkisn’t a good column name as it is a reserved keyword, and the datetype doesn’t take a size parameter. This should work: CREATE PROCEDURE dbo.storMember ( @Check nchar (1), @UserName nvarchar (15), @Passowerd nvarchar (15)=null, @Name nvarchar (15)=null, @Phone nvarchar (15)=null, @email nvarchar (30)=null, … Read more

[Solved] Custom hierarchy

Here is a generic method regardless of the level of the hierarchy. SQL — DDL and sample data population, start DECLARE @tbl table ( idGeo INT IDENTITY PRIMARY KEY, GEO VARCHAR(64), PARENTID INT ); insert into @tbl (GEO, PARENTID) values ( ‘EMEA’, NULL), ( ‘France’, 1), ( ‘mIDCAPSfRANCE’, 2), ( ‘Germany’, 1), ( ‘France exl … Read more

[Solved] GROUP BY problem with varchar

The endings are different 7​i18704 5​i18704 4​i18704 Following your comment I have updated and they GROUP as expected. What do you get when you try this? CREATE TABLE #Advertisements ( ID INT IDENTITY(1,1), Url VARCHAR(200) ) INSERT INTO #Advertisements VALUES (‘http://example.com’) INSERT INTO #Advertisements VALUES (‘http://example.com’) INSERT INTO #Advertisements VALUES (‘http://example.com’) SELECT COUNT(*) c, Url … Read more

[Solved] How to calculate time spent (Timestamp) query, in T-SQL , SQL Server

I’m not sure what you’ve tried so far but based on your sample data, try this: SELECT UserID, SessionID, MIN(timestamp) StartTime, MAX(timestamp) EndTime, DATEDIFF(s,MIN(timestamp), MAX(timestamp)) SecondsDifference FROM Table GROUP BY UserID, SessionID This kind of data is usually tricky because you don’t have the luxury of a sessionid, or the sessionid doesn’t truly reflect what … Read more

[Solved] Need query to start at the beginning of the month

You could calculate the 1st of the month using EOMONTH something like this SELECT DISTINCT ATB.AcountCountDesc,TB.LastFirstName,N.EMAIL,TB.AccountNumber,TB.OpenShareCount,TB.MemberOpenDate, TB.OpenMemberCount,TB.OpenShareBalance,SH.ShareType,FORMAT(SH.ShareOpenDate,’MM/dd/yyyy’) AS “ShareOpenDate”, SH.ShareCreatedByUser,SH.ShareCreatedByUserName,SH.ShareBranchName,SH.ShareBranch,cast(month(SH.ShareOpenDate) as varchar) + “https://stackoverflow.com/” + cast(year(SH.ShareOpenDate) as varchar)as ‘Open Period’, CONCAT(SH.ShareCreatedByUser,’-‘,SH.ShareCreatedByUserName) ‘Opened By’ FROM arcu.vwARCUOperationMemberTrialBalance as TB JOIN arcu.vwARCUOperationMemberAccountTrialBalance as ATB ON TB.MemberSuppID = ATB.MemberID and TB.ProcessDate = ATB.PDate and TB.MemberStatus = 0 — Account … Read more

[Solved] SQL query to get time spent on specific statuses based on single datetime column [closed]

with SQL Server you can use those very usefull windowed functions LEAD and FIRST_VALUE : select * ,[duration(sec)] = DATEDIFF(SECOND ,ticketTime ,LEAD(ticketTime,1,ticketTime)over(partition by ticketNumber order by ticketTime) ) ,[cumulative duration(sec)] = DATEDIFF( SECOND , FIRST_VALUE(ticketTime)over(partition by ticketNumber order by ticketTime) , ticketTime) from (values (1,cast(‘20211101 10:00:01′ as datetime)) ,(1,’20211101 10:00:33′) ,(1,’20211101 10:01:59’) )T(ticketNumber,ticketTime) ticketNumber ticketTime … Read more

[Solved] Get first day of week T-SQL

DECLARE @YEAR int = 2020; DECLARE @WEEKSTOADD int = 6; SET DATEFIRST 1; SELECT DATEADD(day, 1 – DATEPART(dw,DATEADD(week,@WEEKSTOADD,cast(cast(@YEAR as varchar(4)) + ‘0101’ as date))), DATEADD(week,@WEEKSTOADD,cast(cast(@YEAR as varchar(4)) + ‘0101’ as date))) 3 solved Get first day of week T-SQL

[Solved] Trouble writing a select query [closed]

It looks like vb code if you want c# code then use following code cmd = new SqlCommand(“select name from wq where id='” + TextBox1.Text + “‘”, con); con.Open(); dr = cmd.ExecuteReader(); dr.Read(); TextBox2.Text = dr[0].ToString(); dr.Close(); con.Close(); 7 solved Trouble writing a select query [closed]

[Solved] If I have two columns, how can I select all distinct values of columnA where columnB is never a specific value given that columnA is the same value?

If I have two columns, how can I select all distinct values of columnA where columnB is never a specific value given that columnA is the same value? solved If I have two columns, how can I select all distinct values of columnA where columnB is never a specific value given that columnA is the … Read more

[Solved] Break down long multi day periods of time into several single day periods

The method I have used here is a Tally Table to create extra rows. I JOIN onto the tally table where the number of hours / 24 (integer maths is useful) is greater than the tally number, and then can use that to calculate the hours. WITH YourTable AS( SELECT * FROM (VALUES(1,CONVERT(date,’2018/01/24′,111),4 ), (2,CONVERT(date,’2018/03/21′,111),40), … Read more

[Solved] SQL query for display one field only once which having multiple record

Using CASE Condition and Row_number we can achieve the above Output It’s Purely based on your sample Data DECLARE @Table1 TABLE (projName varchar(1), percentage int) ; INSERT INTO @Table1 (projName, percentage) VALUES (‘A’, 10), (‘A’, 25), (‘B’, 20), (‘B’, 30) ; Select CASE WHEN RN = 1 THEN projName ELSE NULL END projName, percentage from … Read more