Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
From this code I get an error in "name,category,price" on "name" like this :
create database coffee
create table items(
iid int identity(1,1) primary key,
name varchar(250) not null,
category varchar(250) not null,
price bigint not null
);
name,category,price
select * from items
Help please
I think what you are after is:
select name,category,price from items
This is due to you wanting to select those 3 values from the database.
Whereas
name,category,price /*Not sure what this does */
select * from items /* This means select all columns from the table */
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
drop table if exists #PercentPopulationVaccinated
create table #PercentPopulationVaccinated
(
Continent nvarchar(255),
location nvarchar(255),
date datetime,
population numeric,
new_vaccinations numeric,
rolling_people_vaccinated numeric
)
Insert into
Select
dea.continent, dea.location, dea.date, dea.population,
vac.new_vaccinations,
sum(convert(int, vac.new_vaccinations)) over (partition by dea.location order by dea.location, dea.date) as rolling_people_vaccinated
from
PortfolioProject..['Covid vaccinations$'] vac
Join
PortfolioProject..['Covid deaths$'] dea on dea.location = vac.location
and dea.date = vac.date
where
dea.continent is not null
--order by 2,3
Select
*,
(rolling_people_vaccinated / Population) * 100
from
#PercentPopulationVaccinated
I keep getting this error
Msg 156, Level 15, State 1, Line 115
Incorrect syntax near the keyword 'Select'
Please advise
You have to write where you want insert data:
INSERT INTO #PercentPopulationVaccinated
SELECT ...
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am puzzled with the use of % wildcard in variables.
For instances this will work:
SELECT *
FROM TABLE
WHERE column LIKE 'blah%'
But this will not:
DECLARE #myvar AS varchar = 'blah%'
SELECT *
FROM TABLE
WHERE column LIKE #myvar
What am I missing here?
Thanks!
By declaring as a variable the wildcard becomes just another literal. Also, a length should be assigned to the VARCHAR. Then this works
DECLARE #myvar varchar(10) = 'blah'
SELECT * FROM TABLE WHERE column like #myvar+'%'
Please see this WORKING example
drop table if exists #Stock;
go
create table #Stock(
some_col varchar(10) not null);
insert #Stock(some_col) values ('Stock abc'),('Stock abc'),('Stock abc');
DECLARE #myvar varchar = 'Stock%';
SELECT * FROM #Stock WHERE some_col like #myvar;
DECLARE #myvar2 varchar = 'Stock';
SELECT * FROM #Stock WHERE some_col like #myvar2+'%';
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
SQL Server creating table error.
How to give system date, system date + 2 days while creating a table?
Is the system date the same as the current date?
You can try the SQL DEFAULT Constraint as shown below if I understood your question properly:
Create table Test(id int
, name varchar(20)
, dtDate datetime default DateAdd(dd, 2, getdate()))
insert into Test (id, name) values
(1, 'A')
select * from Test
Live db<>fiddle demo.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
In sql server, when I create a column like:
select *, '1' as test
what is the type of this new column i.e 1 ?
Just one more question, can I reference this column on other table?
For SQL Server, you can answer such questions easily using sp_describe_first_result_set:
exec sp_describe_first_result_set N'select *, ''1'' as test from sys.objects'
Produces a result set, the last row of which indicates that the test column in that result set is of type varchar(1). (Other results in this case, pulling the other columns from the sys.objects table make it clear that this procedure is capable of describing columns as non-var char(2) or nvarchar(128), so it's not just a display issue)
This column has char(1) type and yes u can use this column in joins or other manipulation etc as well.
because its value is a string within ' ' If you want it to be an integer. you can do the following:
select *, Cast(1 as INT) as test FROM SomeTable
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
Here is pics of Relationship and Pasenger_detail form and i wrote query to select seat_no but its not working properly. it is only showing all seats as per bus reserved id. but requirement were to show only those which are not yet selected. here is query
"Select seat_no.seat_no FROM Seat_No Where seat_no.seat_no <= (select br_info.Seats_Reserved from br_info where ((Br_info.br_id)=[forms]![pasenger_detail]![br_id]) AND (Seat_No.seat_no) NOT IN (SELECT Pasenger_Detail.Seat_No FROM Pasenger_Detail WHERE (((Pasenger_Detail.Group_ID)=[forms]![Pasenger_Detail]![Group_ID]) AND ((Pasenger_Detail.BR_ID)=[forms]![Pasenger_Detail]![BR_ID]))));"
SELECT S.Seat_No
FROM Seat_No AS S
WHERE S.Seat_No Not In
(
SELECT P.Seat_No
FROM BR_Info AS B INNER JOIN Pasenger_Detail AS P ON B.BR_ID = P.BR_ID
WHERE B.BR_ID = Forms!pasenger_detail!BR_ID
AND B.Group_ID = Forms!Pasenger_Detail!Group_ID
)
In the above query I am joining BR_Info and Passenger_Detail together. It is an INNER JOIN which means that the record has to exist in both BR_Info and Passenger_Detail in order to be considered. Then I am using Not In to get all the Seat_No that are not contained in the sub query.