I need a sql query that gets the precision value for certain columns.. I am mainly concerned with a decimal type column and I need the precision value for the same. I realise that it is possible to do so in certain versions and vendors of database servers. It would be nice if you could list down for a few
Creating and Selecting table variables dynamically in SQL Server stored procedure?
Please guide me how to create table variables dynamically. I know it can be like this: How I will create if dont know columns and data types. Scenario is I have to create table variable as per a physical tables and selct data into them, use them in SP and then return data in table variables to C# program. For
Find a string within an array column in PostgreSQL
I have built a series of views in a PostgreSQL database that includes a couple of array columns. The view definition is as follows: create view articles_view as (select articles.*, array(…
Drop a temporary table if it exists
I have two lines of code in SQL that create two tables on the fly, i need to do something like IF TABLE EXISTS DROP IT AND CREATE IT AGAIN ELSE CREATE IT my lines are the following ones …
Delete all records except the most recent one?
I have two DB tables in a one-to-many relationship. The data looks like this: Resultset: I want to delete all applications except for the most recent one. In other words, each student must only have one application linked to it. Using the above example, the data should look like this: How would I go about con…
Best practices of structuring stored procedures
As a developer mainly writing c# I have adopted some good practices when writing c# code. When I sometimes write stored procedures I have trouble applying those practices to the stored procedure code. …
MySQl Query: copy a column named ‘C’ from table2 to column ‘C’ in table1 without losing any other column data
I have 2 tables table1 and table2. I have to copy a column named ‘C’ from table2 to column ‘C’ in table1 without losing any other column data. Both field data types are same. Can anybody give me a …
How to alter a column’s data type in a PostgreSQL table?
Entering the following command into a PostgreSQL interactive terminal results in an error: What is the correct command to alter the data type of a column? Answer See documentation here: http://www.postgresql.org/docs/current/interactive/sql-altertable.html
Return sql rows where field contains ONLY non-alphanumeric characters
I need to find out how many rows in a particular field in my sql server table, contain ONLY non-alphanumeric characters. I’m thinking it’s a regular expression that I need along the lines of [^a-zA-Z0-9] but Im not sure of the exact syntax I need to return the rows if there are no valid alphanumer…
SQL query for finding records where count > 1
I have a table named PAYMENT. Within this table I have a user ID, an account number, a ZIP code and a date. I would like to find all records for all users that have more than one payment per day with …