Set SQL WHERE value using an element from a list [closed] - sql

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
I have a variable with a list on it and I need to use its value for my find option. I get an error when I set my id_user to id_u.
Here is the list
id_u = user_key[0]
This is my SELECT and WHERE
find = ("SELECT * FROM hashtags WHERE id_user=id_u")

You have to concatenate SELECT string with variable value.
Try like this:
id_u = user_key[0]
find = ("SELECT * FROM hashtags WHERE id_user=" + id_u)

Related

Getting different address within same table [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 months ago.
Improve this question
I'm trying to show the miles between an origin and destination. Problem is I'm having trouble writing the query to properly show the destination address. There is only one location table which holds the address of both origin and destination. What am I doing wrong here?
I thought I would get the proper address for the destination and/or location but it's not working.
select dist.DistanceId,
dist.OriginLocationId,
l.Address,
dist.DestinationLocationId,
l.Address,
dist.DistanceInMiles
from DistanceMatrixFromGoogleMapsApi as dist
join locations as l
on l.id = dist.OriginLocationId or l.id = dist.DestinationLocationId
where OriginLocationId in (30506,53097,30362,30505,30377,30378,30594,30379,30514,30518,30517,55055,30360,30515,30516,30616,30512,30511,30510,30513,30381,49129)
and DestinationLocationId in (53097,30362,30505,30377,30378,30594,30379,30514,30518,30517,55055,30360,30515,30516,30616,30512,30511,30510,30513,30381,49129,34690)
These are the results I get
As suggested by #Larnu -
SELECT
dist.DistanceId,
dist.OriginLocationId,
orig.Address,
dist.DestinationLocationId,
dest.Address,
dist.DistanceInMiles
FROM DistanceMatrixFromGoogleMapsApi as dist
JOIN locations as orig
ON dist.OriginLocationId = orig.id
JOIN locations as dest
ON dist.DestinationLocationId = dest.id
WHERE dist.OriginLocationId in (30506,53097,30362,30505,30377,30378,30594,30379,30514,30518,30517,55055,30360,30515,30516,30616,30512,30511,30510,30513,30381,49129)
AND dist.DestinationLocationId in (53097,30362,30505,30377,30378,30594,30379,30514,30518,30517,55055,30360,30515,30516,30616,30512,30511,30510,30513,30381,49129,34690)

Server SQL how to clean column using STUFF? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
608A
608 A
17113 R
16524 DC1
ASM-1780
234604A - Low L2 Cu
19658B-->
234605 - High L2 Cu
17015 Rev A 405734UD0A
43224A (W
23809 REVB
Is there an SQL server query that cleans the column above and removes the excess content on the right such that the data is converted to below:
608
608
17113
16524
ASM-1780
234604
19658
234605
17015
43224
23809
I have tried using STUFF, but it doesn't clean well.
You seem to want everything up to and including the first digit followed by a non-digit.
Well, this returns what you are asking for:
select str, left(str, patindex('%[0-9][^0-9]%', str + ' '))
Here is a db<>fiddle.

How to create a data frame from a text file [closed]

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
I am having trouble creating a data frame with the following data:
Force (N) microstrain1 microstrain2 microstrain3 microstrain4 microstrain5
24.838 9.689 -20.299 19.785 15.601 -7.681
49.691 22.610 -40.797 41.304 32.200 -15.332
75.309 33.357 -61.678 62.512 48.726 -22.422
97.227 41.944 -80.524 81.011 62.266 -30.228
121.641 52.692 -100.775 100.703 77.248 -36.884
Every time I try to use a delimiter I get the following message:
/Users/macbookpro/PycharmProjects/Projects/Lab_3/Bending.py:5: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.
df1 = pd.read_csv('MEE322-thurs_1040_group1_9.5cm.txt',delimiter=' ')
Did you try the python engine instead of the c engine?:
df1 = pd.read_csv('MEE322-thurs_1040_group1_9.5cm.txt', delimiter=' ', engine='python')

Restrict data to logged in user asp.net [closed]

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
I am creating a medication ordering website as part on an assignment. I have a link table that contains the users id and medication id.
When a user is logged in I want them to see their medication only
SELECT [MedicineId] FROM [Prescription] WHERE ([PatientId] = #PatientId)
I have not created a log in yet because I dont want to log in every time im testing.
[![tables][2]][2]
You can use Session for a sample patient.
Session["PatientId"] = 1453;
var SqlQuery = "SELECT [MedicineId] FROM [Prescription] WHERE [PatientId] =" + Session["PatientId"].ToString();
With SQL Parameters
var SqlQuery = "SELECT [MedicineId] FROM [Prescription] WHERE [PatientId] = #PatientId";
var connection = new SqlConnection(/* your DB connection */);
var command = new SqlCommand(SqlQuery, connection);
command.Parameters.AddWithValue(
"PatientId", Session["PatientId"].ToString());

error with the " .... WHERE A = 'B' request [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am using SQL server 2008. I have a database (table name :Data) where one column's name is title and another one is date.
One of the entry in the first column is :
WOLVERINE LE COMBAT DE L'IMMORTEL
However here what is not working :
select date from Data where title = 'WOLVERINE LE COMBAT DE L''IMMORTEL'
select date , title from Data where title LIKE '%WOLVERINE LE COMBAT DE L''IMMORTEL%'
select date , title from Data where title LIKE '%WOLVERINE LE%'
Here what is working :
select date , title from Data where title LIKE '%WOLVERINE%'
select date , title from Data where title LIKE '%LE COMBAT DE L''IMMORTEL%'
select date , title from Data where title LIKE '%WOLVERINE LE%'
Yes, it works for 'WOLVERINE LE' when there is two spaces, even though I am pretty sure there is only one space in the database ( that is the case when I do a request).
Does someone know how come there is this error ?
EDIT : Well sorry it seems like there was really two spaces between them, when I tried to display it in my aspx page, the two spaces are automatically replaced with one space, that is why I could not see it.
If you have any confusion about the no. of spaces then just remove all the white space form both the sides
select date
from Data
where REPLACE(title,' ','') = REPLACE('WOLVERINE LE COMBAT DE L''IMMORTEL',' ','')