select-query

SQL Server PRINT SELECT (Print a select query result)?

早过忘川 提交于 2019-11-30 02:39:13
I am trying to print a selected value, is this possible? Example: PRINT SELECT SUM(Amount) FROM Expense You know, there might be an easier way but the first thing that pops to mind is: Declare @SumVal int; Select @SumVal=Sum(Amount) From Expense; Print @SumVal; You can, of course, print any number of fields from the table in this way. Of course, if you want to print all of the results from a query that returns multiple rows, you'd just direct your output appropriately (e.g. to Text). If you're OK with viewing it as XML: DECLARE @xmltmp xml = (SELECT * FROM table FOR XML AUTO) PRINT CONVERT

How can I select from list of values in SQL Server

╄→尐↘猪︶ㄣ 提交于 2019-11-27 05:55:57
I have very simple problem that I can't solve. I need to do something like this: select distinct * from (1, 1, 1, 2, 5, 1, 6). Anybody can help?? Edit The data comes as a text file from one of our clients. It's totally unformatted (it's a single, very long line of text), but it may be possible to do so in Excel. But it's not practical for me, because I will need to use these values in my sql query. It's not convenient to do so every time I need to run a query. Simplest way to get the distinct values of a long list of comma delimited text would be to use a find an replace with UNION to get the

Using an IF Statement in a MySQL SELECT query

☆樱花仙子☆ 提交于 2019-11-27 01:49:15
I am trying to use an IF statement in a MySQL select query. I am getting an error after the AND statement where the first IF . SELECT J.JOB_ID,E.COMPANY_NAME,J.JOB_DESC,JT.JOBTYPE_NAME,J.COMPENSATION,ST.STATE_NAME,MC.METRO_CITY_NAME,I.INDUSTRY_NAME, J.JOB_CONTACT_PERSON,J.DT_INSRT,J.JOB_TITLE,J.JOB_EXP_DATE,J.SKILLS FROM JOBS J JOIN EMPLOYER E ON J.COMPANY_ID=E.COMPANY_ID JOIN LOOKUP_JOBTYPE JT ON J.JOB_TYPE=JT.JOBTYPE_ID JOIN LOOKUP_STATE ST ON J.STATE_ID=ST.STATE_ID JOIN JOBS_LOCATION JL ON J.JOB_ID=JL.JOB_ID JOIN LOOKUP_METRO_CITY MC ON JL.METRO_CITY_ID=MC.METRO_CITY_ID JOIN LOOKUP_INDUSTRY

MySQL floating point comparison issues

落爺英雄遲暮 提交于 2019-11-26 22:58:10
I ran into an issue by introducing floating point columns in the MySQL database schema that the comparisons on floating point values don't return the correct results always. 1 - 50.12 2 - 34.57 3 - 12.75 4 - ...(rest all less than 12.00) SELECT COUNT(*) FROM `users` WHERE `points` > "12.75" This returns me "3". I have read that the comparisons of floating point values in MySQL is a bad idea and decimal type is the better option. Do I have any hope of moving ahead with the float type and get the comparisons to work correctly? Do you notice the problem below? CREATE TABLE a (num float); INSERT

Using an IF Statement in a MySQL SELECT query

依然范特西╮ 提交于 2019-11-26 09:45:56
问题 I am trying to use an IF statement in a MySQL select query. I am getting an error after the AND statement where the first IF . SELECT J.JOB_ID,E.COMPANY_NAME,J.JOB_DESC,JT.JOBTYPE_NAME,J.COMPENSATION,ST.STATE_NAME,MC.METRO_CITY_NAME,I.INDUSTRY_NAME, J.JOB_CONTACT_PERSON,J.DT_INSRT,J.JOB_TITLE,J.JOB_EXP_DATE,J.SKILLS FROM JOBS J JOIN EMPLOYER E ON J.COMPANY_ID=E.COMPANY_ID JOIN LOOKUP_JOBTYPE JT ON J.JOB_TYPE=JT.JOBTYPE_ID JOIN LOOKUP_STATE ST ON J.STATE_ID=ST.STATE_ID JOIN JOBS_LOCATION JL ON

How can I select from list of values in SQL Server

 ̄綄美尐妖づ 提交于 2019-11-26 08:43:32
问题 I have very simple problem that I can\'t solve. I need to do something like this: select distinct * from (1, 1, 1, 2, 5, 1, 6). Anybody can help?? Edit The data comes as a text file from one of our clients. It\'s totally unformatted (it\'s a single, very long line of text), but it may be possible to do so in Excel. But it\'s not practical for me, because I will need to use these values in my sql query. It\'s not convenient to do so every time I need to run a query. 回答1: Simplest way to get

MySQL floating point comparison issues

有些话、适合烂在心里 提交于 2019-11-26 08:29:02
问题 I ran into an issue by introducing floating point columns in the MySQL database schema that the comparisons on floating point values don\'t return the correct results always. 1 - 50.12 2 - 34.57 3 - 12.75 4 - ...(rest all less than 12.00) SELECT COUNT(*) FROM `users` WHERE `points` > \"12.75\" This returns me \"3\". I have read that the comparisons of floating point values in MySQL is a bad idea and decimal type is the better option. Do I have any hope of moving ahead with the float type and