Skip to content

Tag: sql

SQLAlchemy Column Types As Generic (BIT Type)

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

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…

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…