sql

Sql Server union with If condition

天涯浪子 提交于 2021-02-18 09:31:33
问题 I have a query like: DECLARE @tmpValue SET @tmpValue = 0 -- it will be change SELECT * FROM Animal WHERE AniActive = 1 UNION IF @tmpValue > 0 SELECT * FROM Animal WHERE.Active = 0 When I use like this it is giving error because of if condition. I have to use UNION because of our structure. How can I use it with if condition? Thanks, John 回答1: Move the condition @tmpValue > 0 to the WHERE clause like so: SELECT * FROM Animal WHERE AniActive = 1 UNION SELECT * FROM Animal WHERE @tmpValue > 0

Sql Server union with If condition

旧时模样 提交于 2021-02-18 09:31:11
问题 I have a query like: DECLARE @tmpValue SET @tmpValue = 0 -- it will be change SELECT * FROM Animal WHERE AniActive = 1 UNION IF @tmpValue > 0 SELECT * FROM Animal WHERE.Active = 0 When I use like this it is giving error because of if condition. I have to use UNION because of our structure. How can I use it with if condition? Thanks, John 回答1: Move the condition @tmpValue > 0 to the WHERE clause like so: SELECT * FROM Animal WHERE AniActive = 1 UNION SELECT * FROM Animal WHERE @tmpValue > 0

How to calculate square root in sqlite

こ雲淡風輕ζ 提交于 2021-02-18 09:01:56
问题 I need to calculate an euclidean distance in a sqlite database. Does anyone know how to calculate square roots in sqlite beside writing and loading a dynamic library for math functions? I am close to resorting to the fast inverse square root algorithm in here http://en.wikipedia.org/wiki/Fast_inverse_square_root though it might to turn into more fun than I need right now. And as a side note, it'd be great to figure out how to do power (which is the generalized question, and is cleaner coding

Select values which not in another table with Django

我只是一个虾纸丫 提交于 2021-02-18 06:14:33
问题 How this SQL query can be translated to Django ORM statement? SELECT field1, field2, field3 FROM table1 WHERE field1 NOT IN (SELECT 2_field1 FROM table2); Kindly help! :) ps table1 and table2 not bounded with ForeignKey or ManyToMany 回答1: Using two QuerySets, as shown in the docs. inner_qs = table2.objects.all() results = table1.objects.exclude(field1__in=inner_qs) 来源: https://stackoverflow.com/questions/14105660/select-values-which-not-in-another-table-with-django

Select values which not in another table with Django

僤鯓⒐⒋嵵緔 提交于 2021-02-18 06:14:17
问题 How this SQL query can be translated to Django ORM statement? SELECT field1, field2, field3 FROM table1 WHERE field1 NOT IN (SELECT 2_field1 FROM table2); Kindly help! :) ps table1 and table2 not bounded with ForeignKey or ManyToMany 回答1: Using two QuerySets, as shown in the docs. inner_qs = table2.objects.all() results = table1.objects.exclude(field1__in=inner_qs) 来源: https://stackoverflow.com/questions/14105660/select-values-which-not-in-another-table-with-django

Automatically generate a user defined table type that matches an existing table

巧了我就是萌 提交于 2021-02-18 05:16:44
问题 I have several tables that already exist in my database. Some of them have quite a few columns. I want to make some stored procedures to do a merge statement with these tables. To do that I would like the parameter of the stored procedure to be a User Defined Table type. I can go script out each table and modify it to a User Defined Table Type Creation statement. But what I would really like is a way to generate a user defined table type off an existing table in my database. I could then add

Automatically generate a user defined table type that matches an existing table

本秂侑毒 提交于 2021-02-18 05:16:29
问题 I have several tables that already exist in my database. Some of them have quite a few columns. I want to make some stored procedures to do a merge statement with these tables. To do that I would like the parameter of the stored procedure to be a User Defined Table type. I can go script out each table and modify it to a User Defined Table Type Creation statement. But what I would really like is a way to generate a user defined table type off an existing table in my database. I could then add

How to add parameter values to pgadmin sql query?

梦想的初衷 提交于 2021-02-18 04:08:51
问题 In pgadmin3, I would like to use parameterized queries (to faster debugging, just copy & paste the query from my php file). But I haven't found an option to add the values of the $1 , $2 ... parameters. Is it possible? This is the query I'm building in a loop, following the suggestion for NULL testing from here: SELECT EXISTS(SELECT 1 FROM tax WHERE (addby=$1 or addby<>$1) AND (adddate=$2 or adddate<>$2) AND ($3 IS NULL AND nome IS NULL OR nome=$3) AND ($4 IS NULL AND rank IS NULL OR rank=$4)

Joining 4 Tables in SQL Server Using Join

南笙酒味 提交于 2021-02-18 02:03:54
问题 Hi Friends I have to join 4 tables in SQL Server and need to Show Specific Coulmns in Data Grid View First Table : emp_details Second Table : tbl_designation Third Table : tbl_empcontribution Forth table : tbl_empdeduction Columns need to show in Data Grid View is 1.From First Table i need to show emp_id, emp_name , emp_pf 2.from Second Table i need to show designation_name 3.from third Table i need to show pfacc1 and pfacc2 4.From Fourth Table i need to show pf_percent and pf_max Try to

Joining 4 Tables in SQL Server Using Join

被刻印的时光 ゝ 提交于 2021-02-18 02:00:52
问题 Hi Friends I have to join 4 tables in SQL Server and need to Show Specific Coulmns in Data Grid View First Table : emp_details Second Table : tbl_designation Third Table : tbl_empcontribution Forth table : tbl_empdeduction Columns need to show in Data Grid View is 1.From First Table i need to show emp_id, emp_name , emp_pf 2.from Second Table i need to show designation_name 3.from third Table i need to show pfacc1 and pfacc2 4.From Fourth Table i need to show pf_percent and pf_max Try to