select-into

Building a comma-separated list of values in an Oracle SQL statement

北城余情 提交于 2019-11-27 07:28:33
问题 I'm trying to build a comma-separated list of values out of a field in Oracle. I find some sample code that does this: DECLARE @List VARCHAR(5000) SELECT @List = COALESCE(@List + ', ' + Display, Display) FROM TestTable Order By Display But when I try that I always get an error about the FROM keyword not being were it was expected. I can use SELECT INTO and it works but if I have more than one row I get the fetch error. Why can't I do as follows: SELECT myVar = Field1 FROM myTable 回答1: In

Preserving ORDER BY in SELECT INTO

 ̄綄美尐妖づ 提交于 2019-11-27 05:34:11
I have a T-SQL query that takes data from one table and copies it into a new table but only rows meeting a certain condition: SELECT VibeFGEvents.* INTO VibeFGEventsAfterStudyStart FROM VibeFGEvents LEFT OUTER JOIN VibeFGEventsStudyStart ON CHARINDEX(REPLACE(REPLACE(REPLACE(logName, 'MyVibe ', ''), ' new laptop', ''), ' old laptop', ''), excelFilename) > 0 AND VibeFGEventsStudyStart.MIN_TitleInstID <= VibeFGEvents.TitleInstID AND VibeFGEventsStudyStart.MIN_WinInstId <= VibeFGEvents.WndInstID WHERE VibeFGEventsStudyStart.excelFilename IS NOT NULL ORDER BY VibeFGEvents.id The code using the

SELECT INTO and “Undeclared variable” error

随声附和 提交于 2019-11-26 11:15:52
问题 When I try to execute following query: SELECT id_subscriber INTO newsletter_to_send FROM subscribers I get an error: #1327 - Undeclared variable: newsletter_to_send What is wrong with that query ? 回答1: INSERT ... SELECT http://dev.mysql.com/doc/refman/5.1/en/insert-select.html INSERT INTO newsletter_to_send SELECT id_subscriber FROM subscribers PS: are you sure you don't need in WHERE clause? 回答2: MySQL does not support the SELECT ... INTO ... syntax. You have to use the INSERT INTO ...

Preserving ORDER BY in SELECT INTO

别来无恙 提交于 2019-11-26 09:58:36
问题 I have a T-SQL query that takes data from one table and copies it into a new table but only rows meeting a certain condition: SELECT VibeFGEvents.* INTO VibeFGEventsAfterStudyStart FROM VibeFGEvents LEFT OUTER JOIN VibeFGEventsStudyStart ON CHARINDEX(REPLACE(REPLACE(REPLACE(logName, \'MyVibe \', \'\'), \' new laptop\', \'\'), \' old laptop\', \'\'), excelFilename) > 0 AND VibeFGEventsStudyStart.MIN_TitleInstID <= VibeFGEvents.TitleInstID AND VibeFGEventsStudyStart.MIN_WinInstId <=