I have the following table: employees employee emp_id manager manager_id a 1 x 1 b 2 a 1 c 3 b 2 I am trying to show x 1 is the top …
Tag: sql-server
What does the two dot before a table name mean
I’ve seen a query that looks like this: Select Id from ..TableName where [Name] = @MyName I can’t seem to find when, or why this would be used. The query session is run against a database (So there …
Dynamically Updating Columns with new Data
I am handling an SQL table with over 10K+ Values, essentially it controls updating the status of a production station over the day. Currently the SQL server will report a new message at the current …
How can I safely create a query that will list column names given a table name, and a connection string which may point to SQL Server or MySQL?
I have the following method at the moment which works for my particular two databases, but I’m not sure if it’s the correct way to achieve my goal of listing column names, or is a bit hacky. One part …
How to extract data from this table and convert it into this specific format using t-sql?
I am using SQL Server 2014. Below is the extract from a table called Table1: ID Market Adult AdultAge 0-5 6-12 13-17 100 UK 1 50 0 0 0 105 UK …
Create a stored procedure which includes return records
I am trying to create a stored procedure which has 3 parameters. Another software will call my procedure with parameters in order to query a bunch of records. The stored procedure includes only a …
INSERT ‘X’ If another column is updated
I need to update column firstname in table Taulu ( removing single quotes ). I also need to add ‘X’ to another column sq if values where updated. I would like to update this in one statement. What I …
Multiple batches in a SQL transaction
I want to create several stored procedures (or user-defined functions) within a transaction. CREATE PROCEDURE statement must be the only statement in the batch, so I have to use following template: …
How to add “or” in SQL select query?
I am creating a report to get customer wise incoming payment in a particular period. Payment can be received through Cheques, Direct Bank Transfers, Cash. This payments saved in the database in a …
How to insert records to temptable which has ;with command in sql?
I have created a temp table which I want to fill with records. Here is my query: create table #temp(companysitetankid int, [SourceGradeName] varchar(50), SiteCode varchar(50)); ;with cst as ( …