Advertisements DECLARE @files TABLE (DocumentID Varchar(50)) INSERT INTO @files (DocumentID) SELECT DISTINCT D.DocumentID FROM Documents D WHERE D.DocumentID IN (‘637542’, ‘655437’, ‘655900’) –example for debugging — loop DECLARE @i INT = 1 DECLARE @rowCount INT = (SELECT COUNT(*) FROM @files) WHILE @i <= @rowCount BEGIN DECLARE @id Varchar(50) = (SELECT DocumentID FROM @files WHERE ROW_NUMBER()… Read More Loop through query results
Advertisements I need to add a new "clmX" column to an existing "tb1" table, which would be a foreign key to another "tb2" table, but some rows will have a null value in the "clmX" column. Which option is better if we are thinking about designing a database: a) – add a new column "clmX"… Read More Add new column or additional table to join two existed tables?
Advertisements So I am making a system for my work and I am struggling on figuring out how to take the Employee_ID and get the First and Last name of the employee and then take the first and last name and combine it to be just the full name. I have already figured out how… Read More How do you get the first and last name from the ID?
Advertisements enter image description here I have this error in the database I don’t know what can cause this. >Solution : This error means there’s another object, likely a primary key, already in the database. You can search your sys.objects to be sure. Run the following query to see where it’s being used: SELECT OBJECT_NAME(parent_object_id)… Read More Databases in SQL Server
Advertisements This: @query = SELECT Count(*) FROM ReportServer$DEVSVR1.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = ‘BASE TABLE’ executes fine if copied into new query window. But fails EXEC @query with this error: Database ‘SELECT Count(*) FROM ReportServer$DEVSVR1’ does not exist. SQL is incorrectly parsing the phrase ‘SELECT Count(*) FROM ReportServer$DEVSVR1’ as the database name. >Solution : EXEC @query means… Read More SQL Server EXEC misinterpreting database name
Advertisements In my database I have a Tracking Codes table as a child of a single Employment table. Along with other data, I am trying to return all of the Tracking Codes in a comma separated string so there will only be one row per Employment. However, I want this string sorted by the Tracking… Read More SQL Server 2019 – Ordering in sub select
Advertisements I have a table in SQL server with data of Courses, WorkingArea and Province and I want to get the count of WorkingArea for each Province and for each course. Could you help me please? For example, there are 2 "Desempleados" in "Almeria" for "Course A", so I want "2" as result in another… Read More How could I obtain a count from multiple colums?
Advertisements SQL Server here. Trying to add a DATETIME column to an existing table, that has a default value of "now minus 12 months" (12 months prior to whatever point in time an insert is made to the table). My best attempt: ALTER TABLE myschema.mytable ADD COLUMN Start_Date datetime NOT NULL DEFAULT DATEADD(month, -12, GETDATE())… Read More SQL Server not allowing datetime column to be added that has a computed default value
Advertisements I want to know the total number of tweets by the hour but it gives me duplicates. SELECT DISTINCT datepart(hh,tweet_created) AS hours_tweeted, COUNT(tweet_text) AS total_tweets FROM [New_years_resolutions_2020] GROUP BY tweet_created ORDER BY total_tweets DESC; hours_tweeted total_tweets 11 16 11 15 12 14 12 13 I want something like this hours_tweeted total_tweets 11 31 12… Read More how can I add up the duplicate values in SQL?
Advertisements I use a script involving googletrans==4.0.0-rc1, there is a problem with this package, which is limited requests. My solution when I connect to SQL server is to create a flag column(what record has been translated and what hasn’t gone through translation), to translate new rows only and append rather than over writing. Is there… Read More Google translate(limited request solution)