SQL: UPDATE by SELECT

Need update t_reports table, column tanked_sum. t_reports – reports table – tanked_sum – sum of tanked from t_vehicles table t_vehicles – vehicles table (more than one vehicle is in one report) – tanked – refueled liters of fuel for one vehicle — select only (count in `tanked_sum_counted` column) SELECT tanked_sum_counted, * FROM t_reports r JOIN ( SELECT Read more about SQL: UPDATE by SELECT[…]

The conversion of a varchar data type to a datetime data type resulted in an out-of-range value (Konwersja typu danych varchar na typ danych datetime spowodowała utworzenie wartości leżącej poza zakresem)

This error can be result of wrong `dateformat` setting on database. Example below. ERROR – `dmy` dateformat: SET DATEFORMAT dmy; DECLARE @datetime datetime = ‘2021-12-31’; SELECT CASE WHEN @datetime >= ‘2021-11-22’ THEN 1 ELSE 0 END;SET DATEFORMAT dmy; DECLARE @datetime datetime = ‘2021-12-31’; SELECT case when @datetime >= ‘2021-11-22’ then 1 else 0 end; OK Read more about The conversion of a varchar data type to a datetime data type resulted in an out-of-range value (Konwersja typu danych varchar na typ danych datetime spowodowała utworzenie wartości leżącej poza zakresem)[…]

update column with random string

DECLARE @v TABLE (x VARCHAR(50)) INSERT INTO @v VALUES — list of strings that column will be updated with (’37845840’),(’34879335’),(’33879336’),(’37855840’);   DECLARE cursor1 CURSOR FOR SELECT <TABLE_ID> FROM <SOME_TABLE>; DECLARE @id INT;   OPEN cursor1 FETCH NEXT FROM cursor1 INTO @id   WHILE @@FETCH_STATUS=0 BEGIN UPDATE <SOME_TABLE> SET <UPDATED_COLUMN> = ( SELECT x FROM ( Read more about update column with random string[…]

SQLCMD.exe

# query in command line sqlcmd -d db_name -Q ‘select * from table_name’ -W   # connnect by hostname and port number (1433) sqlcmd -S tcp:hostname,1433 -U username -P password   # connnect by hostname and port number (1433) and use db (dbname) sqlcmd -S tcp:hostname,1433 -U username -P password -d dbname   # input Read more about SQLCMD.exe[…]

SQL Server: Numer portu

Wykonanie poniższego zapytania powinno zwrócić numery portów, na których nasłuchuje SQL Server. USE master GO xp_readerrorlog 0, 1, N’Server is listening on’, ‘any’, NULL, NULL, N’asc’ GOUSE master GO xp_readerrorlog 0, 1, N’Server is listening on’, ‘any’, NULL, NULL, N’asc’ GO