T-sql syntaxis for sql server

JohnDW

Well-known member
Joined
Jun 13, 2012
Messages
60
Location
Antwerp, Belgium
Programming Experience
1-3

I have an t-sql syntax in sqlservermanagement , but
it doesn't work. The purpose is that when I enter a value (a number that exists out of 2 numbers (dossiernumberjaar and dossiervolgnumber) the record comes:
The follwing code works but then I have to give 2 values (dossiernummer jaar and dossiervolgnummer):
VB.NET:
Expand Collapse Copy
SELECT
 TblDossiers.DossierNummerJaar,TblDossiers.DossierVolgNummer,
tblDossiers.Klantnummer, tblDossiers.Bedrag, tblDossiers.DateUitgeschreven, 
tblDossiers.Uitbetaald, tblDossiers.Uitbetaald, Klant.Naamvoornaam
From tblDossiers Inner Join Klant On tblDossiers.Klantnummer = Klant.Klantnummer
where (DossierNummerJaar = 12 and DossierVolgNummer = 233)
It must be something like this but it doesn't work:
VB.NET:
Expand Collapse Copy
where Cast(DossierNummerJaar As int) + 'R' + CAST(DossierVolgNummer As int) = 12233

Can someone help me?
John
 
The query seems fine, except you forgot table identifiers on the WHERE clause, although they shouldn't be necessary unless the same column name is used in the two tables. In any case, learn to use aliases, it clears up a lot of extra typing. All you really need to do is provide the two parameters through the SqlCommand object. Also the query as is looks for BOTH DossierNummerJaar and DossierVolgNummer. Replace the AND with a OR and you should be fine.

SELECT d.DossierNummerJaar, d.DossierVolgNummer, d.Klantnummer, d.Bedrag, d.DateUitgeschreven, d.Uitbetaald, d.Uitbetaald, k.Naamvoornaam
FROM tblDossiers d
INNER JOIN Klant k ON d.Klantnummer = k.Klantnummer
WHERE d.DossierNummerJaar = @DossierNummerJaar OR d.DossierVolgNummer = @DossierVolgNummer
 
Ok Herman, THise sytax works fine!
But suppose the user wants to add the whole number.
For example if @DossierNummerJaar = 12 and @DossierVolgNummer = 233,
he adds '12233'. ANd the query is lookin in the fields DossierNummerJaar and DossierVOlgNummer .
How I use this in a query:

something like:

VB.NET:
Expand Collapse Copy
[SIZE=2][COLOR=#ff0000][SIZE=2][COLOR=#ff0000]SELECT d.DossierNummerJaar, d.DossierVolgNummer, d.Klantnummer, d.Bedrag, d.DateUitgeschreven, d.Uitbetaald, d.Uitbetaald, k.Naamvoornaam FROM tblDossiers d INNER JOIN Klant k ON d.Klantnummer = k.Klantnummer WHERE (d.DossierNummerJaar + '' + d.DossierVolgNummer) = 12232


[/COLOR][/SIZE][/COLOR][/SIZE]I'm lookin for this query syntaxis so I can use it in my stored procedure.
The query above doesn't work.
Can you help me with that?

Txs,

John
 
Back
Top