I am trying to list out the columns of each table in an MSSQL database. I can get them fine, but I need to turn them into generic types for use elsewhere. (Python types would be more ideal but not sure how to do that?) My code so far works until I come across a BIT type column. I get
Tag: sql
Recode column values in MySQL
I am dealing with a column named UCODE130 that has values anywhere from 1-130. I would like to replace the values with ranges. For example, I want to replace any 1, 2, 3, or 4 found in that column with a string “1 – 4” instead. I do not want to do just a select statement – I want to
MySQL how get middle point between two given times
I have 2 times value 06:00:00 and 14:00:00 expected result is 10:00:00 FYI. I want to write this into my trigger Answer You can convert your times to seconds, then find the middle value, and convert back to time The middle value of two numeric values is simply (a + b) / 2
postgreSQL LEFT and UPPER interaction
Question: Write a query that returns the name, address, state, and zipcode from all purchases. For the names, return only the first 5 characters, and display them in all uppercase letters, sorted in alphabetical order. Code so far: I’m at a loss of where and how to use UPPER to capitalize all the charac…
only displays the data contained in the list (is it possible to use the IN function or something)?
I have 4 tables. suppose the list table is a collection of unique data, then there are 3 other tables, each of which has data where not all of the values are in the list table. list aa bb cc dd ee ff gg hh ii jj group_1 aa cc ff hh group_2 aa bb cc ee jj group_3 aa
SQL with non-existing column in where cause can be executed
Here’s my SQL The issue is, the colA1 does not exist in TableB. So if I just run this Then SQL Server Management Studio will return an error: Invalid column name ‘colA1’. But if it is in the where cause, the first SQL can be executed as if where cause is always true. Answer Thats because SQL…
ORACLE SQL Combining many rows to one and sum a field
ORACLE SQL … I am trying to combine rows into one when they share the same contents in the following fields: In addition, I need the sum of the fields GL_ACCOUNT_BALANCE from all the respective previous rows to be totaled onto that one new row. I have written the following code. Answer From my point of …
Using Right() or Substr() in an UPDATE statement
I have two tables : Second Table : I need to update the field HC_ID of Add_T Table and I use the following SQL statement: It doesn’t work. Also, I used the right() function and also got incorrect results. Could anyone say where is the mistake? Answer Looks like you need the last 4 characters of a string…
SQL – Remove Blanks/nulls rows and combine rows
I want to combine multiple rows into as few rows as possible by removing nulls Current: Table1 want: Table2: Answer For your sample data and results you can use:
How to limit STUFF function within CTE for removing character before recurring word
A follow up question for Replace a recurring word and the character before it Credit to @Larnu for the following code, how would this code be modified to not produce a null value if there is no longer a character before a recurring word, “[BACKSPACE]”. I believe the null value is occurring because…