Skip to content

Tag: sql

SQL query to generate the following output

Display user id, user name, total amount, amount to be paid after discount and give alias name as User_ID, user_name, Total_amount, Paid_amount. Display record in descending order by user id. Click on TABLE SHCEMA to get the table This is the code I’ve written. But this is not showing the expected resul…

MSSql server jpa spatial exception

Is it possible to use sql spatial data in jpa? I ve MS SQL Server 2014 Express Edition. I m trying to use spatial data as follows; maven (pom.xml) dependencies; db dialect; spring.jpa.hibernate.dialect=org.hibernate.spatial.dialect.sqlserver.SqlServer2008SpatialDialect entity definition; @Column(columnDefinit…

MySql search integer range from number with dash

I have table in that I have one field with dash value. Like… I need to search this with between condition. For example if I have one value 25 then I need to search the records which include the value 25 like 20-31. In above image there are 6 records which include 25 value. So it should return 6 records.

Oracle query all_tab_columns.data_default (type LONG)

I have run this query: But it throws an error at column DATA_DEFAULT: ORA-00932: inconsistent datatypes: expected CHAR got LONG 00932. 00000 – “inconsistent datatypes: expected %s got %s” How can I fix that? Thanks! Answer You can’t do anything with a LONG. It’s a PITA that Oracl…

Dynamic SQL output of a query to a variable

I would like to output the result of the dynamic SQL into a variable called @Count but not sure what the syntax or even the code should like to accomplish this. The code looks as follows: thank you Answer You can utilize sp_executesql to execute your count() query, and output it @Count. Try this: One last thi…

SQL invalid Identifier query

I am getting an error that grandvisit is an invalid identifier, and I am unsure if I will get it with other identifiers either. Any light shed on this would be amazing. As I cannot see why it differents from others. Answer You cannot refer the alias names in same select clause where it is generated. To calcul…

SQL basic issue

Part of a larger query. Initially I am getting an invalid parathensis message, I can get rid of this but am them getting invalid identifier error message, even though all the fields I’m using have been called. I am pretty new to SQL so any help would be great!. Answer Please use below there was two issu…

Split comma separated string into rows in mysql

When I have string list like 1, 2, 3… I’d like to use this as one column Is it possible by sql query? ex) SELECT Ids from (1, 2, 3…) <- I know this is not working. Answer Use a subquery of arbitrary digits to split your string.Instead of vals you can use ‘1,2,3’. See it workin…